Datagrid, c# newbie needing help on paging

B

bkhoward

I am a total newbie, but I am trying to get paging working on a datagrid that gets its data through a datatable... The datagrid populates fine with the search button is used; however, when you click on a page number to page data, it just hangs and doesn't do anything. HELP! My code looks like this

private void Page_Load(object sender, System.EventArgs e

// Put user code to initialize the page her



#region Web Form Designer generated cod
override protected void OnInit(EventArgs e

/
// CODEGEN: This call is required by the ASP.NET Web Form Designer
/
InitializeComponent()
base.OnInit(e)


/// <summary
/// Required method for Designer support - do not modif
/// the contents of this method with the code editor
/// </summary
private void InitializeComponent(
{
this.butSubmit.Click += new System.EventHandler(this.butSubmit_Click)
this.butDelete.Click += new System.EventHandler(this.butDelete_Click)
this.butSearch.Click += new System.EventHandler(this.butSearch_Click)
this.butClear.Click += new System.EventHandler(this.butClear_Click)
this.dgResults.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.changePage)
this.dgResults.SelectedIndexChanged += new System.EventHandler(this.dgResults_SelectedIndexChanged)
this.Load += new System.EventHandler(this.Page_Load)


#endregio

private void butSubmit_Click(object sender, System.EventArgs e

GPBusClassLibrary1.Subscription subscription = new GPBusClassLibrary1.Subscription()

if ((reqTitle.IsValid.Equals(true)) &&
(reqDesc.IsValid.Equals(true))



subscription.Title = this.txtSubscriptionTitle.Text.Trim()
subscription.Desc = this.txtSubscriptionDesc.Text.Trim()

subscription.Key = (this.txtKey2.Text.Trim()== "" ? 0 : int.Parse(this.txtKey2.Text.ToString()))

subscription.Save()

this.txtKey2.Text = ""
this.txtSubscriptionDesc.Text = ""
this.txtSubscriptionTitle.Text = ""





private void butDelete_Click(object sender, System.EventArgs e

GPBusClassLibrary1.Subscription subscription = new GPBusClassLibrary1.Subscription()

subscription.Key = int.Parse(this.txtKey2.Text);
subscription.Delete(subscription.Key)

this.txtKey2.Text = ""
this.txtSubscriptionTitle.Text = ""
this.txtSubscriptionDesc.Text = ""


private void butSearch_Click(object sender, System.EventArgs e

// loads top detail are

GPBusClassLibrary1.Subscription subscription = new GPBusClassLibrary1.Subscription()

subscription.Title = this.txtSubscriptionTitle.Text.Trim()
this.titleSearch = subscription.Title; //used for search area belo


subscription.Load(subscription.Title)

this.txtKey2.Text = subscription.Key.ToString()
this.txtSubscriptionDesc.Text = subscription.Desc
this.txtSubscriptionTitle.Text = subscription.Title

this.bindSearchResults()



private void butClear_Click(object sender, System.EventArgs e

GPBusClassLibrary1.Subscription subscription = new GPBusClassLibrary1.Subscription()

this.txtKey2.Text = ""
this.txtSubscriptionTitle.Text = ""
this.txtSubscriptionDesc.Text = ""


private void Button1_Click(object sender, System.EventArgs e




private void dgResults_SelectedIndexChanged(object sender, System.EventArgs e




private void changePage(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e

dgResults.CurrentPageIndex = e.NewPageIndex
// dgResults.DataBind()
this.bindSearchResults()



private void bindSearchResults(


// loads bottom search results datagri

System.Collections.ArrayList Subscriptions = GPBusClassLibrary1.Subscription.Search(this.titleSearch)

System.Data.DataTable dtSubscriptionSearch = new DataTable()
dtSubscriptionSearch.Columns.Add(new System.Data.DataColumn("ID", typeof(System.String)))
dtSubscriptionSearch.Columns.Add(new System.Data.DataColumn("Title", typeof(System.String)))
dtSubscriptionSearch.Columns.Add(new System.Data.DataColumn("Description", typeof(System.String)));

foreach ( object obj in Subscriptions)
{
System.Data.DataRow row = dtSubscriptionSearch.NewRow();
row["ID"] = ((GPBusClassLibrary1.Subscription)obj).Key.ToString();
row["Title"] = ((GPBusClassLibrary1.Subscription)obj).Title.ToString();
row["Description"] = ((GPBusClassLibrary1.Subscription)obj).Desc.ToString();

dtSubscriptionSearch.Rows.Add(row);
}


this.dgResults.DataSource = dtSubscriptionSearch;
this.dgResults.DataBind();


}


}
 
J

jeff

Please refer to this page:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/
vbtskSpecifyingPagingBehaviorInDataGridWebControl.asp

-jl


bkhoward said:
I am a total newbie, but I am trying to get paging working on a datagrid
that gets its data through a datatable... The datagrid populates fine with
the search button is used; however, when you click on a page number to page
data, it just hangs and doesn't do anything. HELP! My code looks like this:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here

}


#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.butSubmit.Click += new System.EventHandler(this.butSubmit_Click);
this.butDelete.Click += new System.EventHandler(this.butDelete_Click);
this.butSearch.Click += new System.EventHandler(this.butSearch_Click);
this.butClear.Click += new System.EventHandler(this.butClear_Click);
this.dgResults.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.changePage);
this.dgResults.SelectedIndexChanged += new System.EventHandler(this.dgResults_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void butSubmit_Click(object sender, System.EventArgs e)
{
GPBusClassLibrary1.Subscription subscription = new GPBusClassLibrary1.Subscription();

if ((reqTitle.IsValid.Equals(true)) &&
(reqDesc.IsValid.Equals(true)))

{

subscription.Title = this.txtSubscriptionTitle.Text.Trim();
subscription.Desc = this.txtSubscriptionDesc.Text.Trim();

subscription.Key = (this.txtKey2.Text.Trim()== "" ? 0 : int.Parse(this.txtKey2.Text.ToString()));

subscription.Save();

this.txtKey2.Text = "";
this.txtSubscriptionDesc.Text = "";
this.txtSubscriptionTitle.Text = "";

}

}

private void butDelete_Click(object sender, System.EventArgs e)
{
GPBusClassLibrary1.Subscription subscription = new GPBusClassLibrary1.Subscription();

subscription.Key = int.Parse(this.txtKey2.Text);
subscription.Delete(subscription.Key);

this.txtKey2.Text = "";
this.txtSubscriptionTitle.Text = "";
this.txtSubscriptionDesc.Text = "";
}

private void butSearch_Click(object sender, System.EventArgs e)
{
// loads top detail area

GPBusClassLibrary1.Subscription subscription = new GPBusClassLibrary1.Subscription();

subscription.Title = this.txtSubscriptionTitle.Text.Trim();
this.titleSearch = subscription.Title; //used for search area below


subscription.Load(subscription.Title);

this.txtKey2.Text = subscription.Key.ToString();
this.txtSubscriptionDesc.Text = subscription.Desc;
this.txtSubscriptionTitle.Text = subscription.Title;

this.bindSearchResults();


}

private void butClear_Click(object sender, System.EventArgs e)
{
GPBusClassLibrary1.Subscription subscription = new GPBusClassLibrary1.Subscription();

this.txtKey2.Text = "";
this.txtSubscriptionTitle.Text = "";
this.txtSubscriptionDesc.Text = "";
}

private void Button1_Click(object sender, System.EventArgs e)
{

}

private void dgResults_SelectedIndexChanged(object sender, System.EventArgs e)
{

}

private void changePage(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
dgResults.CurrentPageIndex = e.NewPageIndex;
// dgResults.DataBind();
this.bindSearchResults();

}

private void bindSearchResults()
{

// loads bottom search results datagrid

System.Collections.ArrayList Subscriptions = GPBusClassLibrary1.Subscription.Search(this.titleSearch);

System.Data.DataTable dtSubscriptionSearch = new DataTable();
dtSubscriptionSearch.Columns.Add(new System.Data.DataColumn("ID", typeof(System.String)));
dtSubscriptionSearch.Columns.Add(new System.Data.DataColumn("Title", typeof(System.String)));
dtSubscriptionSearch.Columns.Add(new System.Data.DataColumn("Description", typeof(System.String)));

foreach ( object obj in Subscriptions)
{
System.Data.DataRow row = dtSubscriptionSearch.NewRow();
row["ID"] = ((GPBusClassLibrary1.Subscription)obj).Key.ToString();
row["Title"] = ((GPBusClassLibrary1.Subscription)obj).Title.ToString();
row["Description"] = ((GPBusClassLibrary1.Subscription)obj).Desc.ToString();

dtSubscriptionSearch.Rows.Add(row);
}


this.dgResults.DataSource = dtSubscriptionSearch;
this.dgResults.DataBind();


}


}
Community Website: http://www.dotnetjunkies.com/newsgroups/
 
B

bkhoward

As far as I can tell, I am doing this..... Does anyone see anything wrong with the code?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top