469,632 Members | 1,784 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,632 developers. It's quick & easy.

Datagrid header databinding problem

Dear all

I am writting following code for binding data to the header template of
the datagrid on the button click event. but it gives me an error object
referance is not set to an item of object

can any one tell me how i can bind data to the header template of the
datagrid on button click event.

private void button1_Click(object sender, System.EventArgs e)
{
selectQuery();
}
private void selectQuery()
{
try
{
string strcondition="WHERE ";
if(checkDistrict_CheckBox.Checked ==true)
{
strcondition = strcondition + " DistrictMaster."+ " districtid = "
+ district_DropDownList.SelectedValue +" and " +"
SectionLineMaster.SectionLineDescription = '" +
resouce_TextBox.Text.Trim() + "' ";
}

if(checkSDO_CheckBox.Checked ==true)
{
if (strcondition.Length 6)
{
strcondition = strcondition + " AND " ;
}

strcondition = strcondition + "SDOMaster."+ " SDOId = " +
SDO_DropDownList.SelectedValue +" and " +"
SectionLineMaster.SectionLineDescription = '" +
resouce_TextBox.Text.Trim() +"'" ;
}

if(checkTaluka_CheckBox.Checked ==true)
{
if (strcondition.Length 6)
{
strcondition = strcondition + " AND " ;
}

strcondition = strcondition +"TalukaMaster."+ "TalukaId ="+
taluka_DropDownList.SelectedValue +" and " +"
SectionLineMaster.SectionLineDescription = '" +
resouce_TextBox.Text.Trim() +"'";
}

if(checkCircle_CheckBox.Checked ==true)
{
if (strcondition.Length 6)
{
strcondition = strcondition + " AND " ;
}

strcondition = strcondition +"CircleMaster."+ "CircleId ="+
circle_DropDownList.SelectedValue +" and " +"
SectionLineMaster.SectionLineDescription = '" +
resouce_TextBox.Text.Trim()+"'" ;
}

if(checkVillage_CheckBox.Checked ==true)
{
if (strcondition.Length 6)
{
strcondition = strcondition + " AND " ;
}

strcondition = strcondition + "VillageMaster."+ "VillageId ="+
village_DropDownList.SelectedValue +" and " +"
SectionLineMaster.SectionLineDescription = '" +
resouce_TextBox.Text.Trim()+"' " ;
}

DataView dv ;
dv =
VS.DAC.PDMO.GeneralDesMng.SearchSectionsLinesByDis trict(strcondition);

if (dv.Count 0)
{
Label number_Label =
(Label)searchResult_DataGrid.FindControl("numHeade r_Label");
number_Label.Text= dv[0]["NumUnit"].ToString();

Label capacity_Label =
(Label)searchResult_DataGrid.FindControl("capHeade r_Label");
capacity_Label.Text =dv[0]["CapUnit"].ToString();

Label address_Label =
(Label)searchResult_DataGrid.FindControl("addrHead er_Label");
address_Label.Text=dv[0]["AddrUnit"].ToString();
}

searchResult_DataGrid.DataSource = dv;
searchResult_DataGrid.DataBind();

}
catch(Exception ex)
{
Response.Write("<script language=Javascriptalert('"+
ex.Message.ToString()+"') ;</script>");
}
}

Aug 1 '06 #1
1 1216
What line is blowing up? Does the DataGrid not exist?

The most common reason for problems with objects on an ASP.NET page is one
of the following:

1. No code behind representation of the object (this is not true for
DataGrid)
2. Improper use of page events (loading every time, forgetting to load,
etc.)
3. Attempting to alter a control that is populated solely by ViewState

Your issue is likely #3. The solution, then, is to cache the data and rebind
to the Grid with your header changes. If you are only loading when
Page.IsPostBack is false and then repopulating on postback with the built in
ViewState mechanism, the object, from your perspective, does not exist.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside of the box!
*************************************************
"Santosh" <Sa***************@yahoo.comwrote in message
news:11*********************@75g2000cwc.googlegrou ps.com...
Dear all

I am writting following code for binding data to the header template of
the datagrid on the button click event. but it gives me an error object
referance is not set to an item of object

can any one tell me how i can bind data to the header template of the
datagrid on button click event.

private void button1_Click(object sender, System.EventArgs e)
{
selectQuery();
}
private void selectQuery()
{
try
{
string strcondition="WHERE ";
if(checkDistrict_CheckBox.Checked ==true)
{
strcondition = strcondition + " DistrictMaster."+ " districtid = "
+ district_DropDownList.SelectedValue +" and " +"
SectionLineMaster.SectionLineDescription = '" +
resouce_TextBox.Text.Trim() + "' ";
}

if(checkSDO_CheckBox.Checked ==true)
{
if (strcondition.Length 6)
{
strcondition = strcondition + " AND " ;
}

strcondition = strcondition + "SDOMaster."+ " SDOId = " +
SDO_DropDownList.SelectedValue +" and " +"
SectionLineMaster.SectionLineDescription = '" +
resouce_TextBox.Text.Trim() +"'" ;
}

if(checkTaluka_CheckBox.Checked ==true)
{
if (strcondition.Length 6)
{
strcondition = strcondition + " AND " ;
}

strcondition = strcondition +"TalukaMaster."+ "TalukaId ="+
taluka_DropDownList.SelectedValue +" and " +"
SectionLineMaster.SectionLineDescription = '" +
resouce_TextBox.Text.Trim() +"'";
}

if(checkCircle_CheckBox.Checked ==true)
{
if (strcondition.Length 6)
{
strcondition = strcondition + " AND " ;
}

strcondition = strcondition +"CircleMaster."+ "CircleId ="+
circle_DropDownList.SelectedValue +" and " +"
SectionLineMaster.SectionLineDescription = '" +
resouce_TextBox.Text.Trim()+"'" ;
}

if(checkVillage_CheckBox.Checked ==true)
{
if (strcondition.Length 6)
{
strcondition = strcondition + " AND " ;
}

strcondition = strcondition + "VillageMaster."+ "VillageId ="+
village_DropDownList.SelectedValue +" and " +"
SectionLineMaster.SectionLineDescription = '" +
resouce_TextBox.Text.Trim()+"' " ;
}

DataView dv ;
dv =
VS.DAC.PDMO.GeneralDesMng.SearchSectionsLinesByDis trict(strcondition);

if (dv.Count 0)
{
Label number_Label =
(Label)searchResult_DataGrid.FindControl("numHeade r_Label");
number_Label.Text= dv[0]["NumUnit"].ToString();

Label capacity_Label =
(Label)searchResult_DataGrid.FindControl("capHeade r_Label");
capacity_Label.Text =dv[0]["CapUnit"].ToString();

Label address_Label =
(Label)searchResult_DataGrid.FindControl("addrHead er_Label");
address_Label.Text=dv[0]["AddrUnit"].ToString();
}

searchResult_DataGrid.DataSource = dv;
searchResult_DataGrid.DataBind();

}
catch(Exception ex)
{
Response.Write("<script language=Javascriptalert('"+
ex.Message.ToString()+"') ;</script>");
}
}

Aug 1 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Scott | last post: by
reply views Thread by mike | last post: by
5 posts views Thread by Laurence | last post: by
reply views Thread by Daniel Doyle | last post: by
4 posts views Thread by Mark Waser | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.