473,386 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 1306
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the...
2
by: DelphiBlue | last post by:
I have a Nested Datagrid that is using a data relations to tie the parent child datagrids together. All is working well with the display but I am having some issues trying to sort the child...
1
by: Webgour | last post by:
Hi, I'm tring to add a column to a datagrid with a linkbutton as header that can be used to sort the column. The column and the linkbutton are added programmatically (see below). However the...
2
by: Scott | last post by:
Hi all. A few days ago i ask this question and got a good quick response. I tried out what they said and it worked. However I have now come to try the same thing in another program and it...
2
by: Nicole | last post by:
I am creating template columns programmatically. I have read the msdn article on this and I'm so close. Article:...
0
by: mike | last post by:
Hi there: I've read an excellent "how to"-article by Microsoft (no. 306227) - partly cited cited at the end of this email). I have implemented the code related to the part "How to Add a...
5
by: Laurence | last post by:
I want to get the column name of a datagrid control. But DataGrid.Columns always return a collection of count 0. Thanks for your help in advance.
0
by: Daniel Doyle | last post by:
Hello and apologies in advance for the amount of code in this post. I've also sent this message to the Sharepoint group, but thought that ASP.NET developers may also be able to help, even though...
4
by: Mark Waser | last post by:
I've discovered a very odd bug when attempting to put a dropdown list in a datagrid. In the page PreRender step, the selected index of the datagrid is successfully set during databinding. Yet,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.