Two datagrids and datagrid_itemdatabound only for 1 of them

Posted by Anu_dgr8 under C# on 7/14/2010 | Views : 1212 | Status : [Member] | Replies : 6
Hi!
i have 2 datagrids -datagrid1 and datagrid2 on my page..and in code-behind i am having datagrid1_ItemDataBound event getting fired on the datagrid1.DataBind() Method(on page load)..On page load i am trying to bind datagrid2 as well..but the control transfers to datagrid1_ItemDataBound event again,which i don want....
Guys Please Help!

Thanks and Regards,
Hoosha Boosha



Responses

Posted by: Raja on: 7/14/2010 [Member] Starter

Up
0
Down
If you are binding the DataGrid2 inside the ItemDataBound of DataGrid1, then again ItemDataBound of DataGrid1 will fire, if you do not want then keep a page level flag variable and assign it to false and in the DataGrid1.ItemDataBound of check for that flag and if its true then only bind the DataGrid2 otherwise do not bind.

Hope this trick will help.

Regards,
Raja, USA

Anu_dgr8, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Anu_dgr8 on: 7/15/2010 [Member] Starter

Up
0
Down
u mean to say i need to keep a flag variable in .aspx page??

Thanks and Regards,
Hoosha Boosha

Anu_dgr8, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Anu_dgr8 on: 7/15/2010 [Member] Starter

Up
0
Down
And 1 more thing i am not binding datagrid2 inside datagrid1_itemdatabound..
my code goes like this:


protected void Page_Load(object sender, EventArgs e)

{
if (!IsPostBack)
{

FillGrid1();
FillGrid2();
}
}

protected void FillGrid1()
{
DataTable dt1 = Select();
datagrid1.DataSource = dt1;
datagrid1.DataBind();

}

protected void FillGrid2()
{

DataTable dt2= Select_grid2();
datagrid2.DataSource = dt2;
datagrid2.DataBind();


}

protected void datagrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{

}
//i want this to get fired only for datagrid1 ,but its firing for datagrid2 also,which i dont want..am i clear?

Thanks and Regards,
Hoosha Boosha

Anu_dgr8, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Anu_dgr8 on: 7/15/2010 [Member] Starter

Up
0
Down
I got it where i was wrong!i was doing a very silly mistake!

Thanks and Regards,
Hoosha Boosha

Anu_dgr8, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raja on: 7/15/2010 [Member] Starter

Up
0
Down
Could you please provide the solution of your problem so that it would help others.

Regards,
Raja, USA

Anu_dgr8, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Anu_dgr8 on: 7/15/2010 [Member] Starter

Up
0
Down
By mistake i had written OnItemDataBound="datagrid1_ItemDataBound" for datagrid2 also..This was really a silly One!

Thanks and Regards,
Hoosha Boosha

Anu_dgr8, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response