Datagrid header databinding problem

S

Santosh

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.SearchSectionsLinesByDistrict(strcondition);

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

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

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

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

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

Cowboy \(Gregory A. Beamer\)

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 said:
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.SearchSectionsLinesByDistrict(strcondition);

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

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

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

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

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

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

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top