Anterko 0 Newbie Poster

Hello.
I have a nested GridView inside of a DataList. I need to enable the paging control of the GridView, but I have no idea where to put the code for it to work. Also I would like to create a function which will do the following: when a user will click on a specific row on the GridView, he will be redirected for the appropriate page. I tried to find answers using google, but I didn't success to understand the samples that I found.
Here is my code:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class SearchCDs : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            localhost.Service my = new localhost.Service();
            DataTable dt = my.BringTable("CDs", "*");
            DataTable dtgv1 = my.BringTable("Songs", "*");
            DataTable dtgv2 = my.BringTable("Songs", "*");
            DataList1.DataSource = dt;
            DataList1.DataBind();
            string[] arrplaylist = null;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                arrplaylist = dt.Rows[i][2].ToString().Split(',');
                for (int j = 0; j < arrplaylist.Length; j++)
                {
                    for (int z = 0; z < dtgv1.Rows.Count; z++)
                    {
                        if (dtgv1.Rows[z][0].GetHashCode() == System.Convert.ToInt32(arrplaylist[j], 10))
                            dtgv1.Rows.RemoveAt(z);
                    }
                }
                for (int j = 0; j < dtgv1.Rows.Count; j++)
                {
                    for (int z = 0; z < dtgv2.Rows.Count; z++)
                    {
                        if (dtgv1.Rows[j][0].GetHashCode() == dtgv2.Rows[z][0].GetHashCode())
                            dtgv2.Rows.RemoveAt(z);
                    }
                }
                ((GridView)DataList1.Items[i].FindControl("gr")).DataSource = dtgv2;
                ((GridView)DataList1.Items[i].FindControl("gr")).DataBind();
                dtgv1 = my.BringTable("Songs", "*");
                dtgv2 = my.BringTable("Songs", "*");
            }
        }
    }



    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "shownhide")
        {
            if (((Button)(DataList1.Items[e.Item.ItemIndex].FindControl("inf"))).Text.Equals("More Info"))
            {
                ((Button)(DataList1.Items[e.Item.ItemIndex].FindControl("inf"))).Text = "Less Info";
                ((GridView)(DataList1.Items[e.Item.ItemIndex].FindControl("gr"))).Visible = true;
                for (int i = 0; i < DataList1.Items.Count; i++)
                {
                    if (i != e.Item.ItemIndex)
                    {
                        ((Button)(DataList1.Items[i].FindControl("inf"))).Text = "More Info";
                        ((GridView)(DataList1.Items[i].FindControl("gr"))).Visible = false;
                    }
                }
            }
            else
            {
                ((Button)(DataList1.Items[e.Item.ItemIndex].FindControl("inf"))).Text = "More Info";
                ((GridView)(DataList1.Items[e.Item.ItemIndex].FindControl("gr"))).Visible = false;
            }
        }
    }

    
}

Please guide me where and what exactly to add to this code in order that the paging function and the select function will work properly. Please write in C#.
Thanks.

Sorry I'm a newbie here and accidentally wrote here and not in asp.net section. I have already posted the thread where it needs to be. Moderators please delete it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.