473,586 Members | 2,566 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(o bject sender, System.EventArg s e)
{
selectQuery();
}
private void selectQuery()
{
try
{
string strcondition="W HERE ";
if(checkDistric t_CheckBox.Chec ked ==true)
{
strcondition = strcondition + " DistrictMaster. "+ " districtid = "
+ district_DropDo wnList.Selected Value +" and " +"
SectionLineMast er.SectionLineD escription = '" +
resouce_TextBox .Text.Trim() + "' ";
}

if(checkSDO_Che ckBox.Checked ==true)
{
if (strcondition.L ength 6)
{
strcondition = strcondition + " AND " ;
}

strcondition = strcondition + "SDOMaster. "+ " SDOId = " +
SDO_DropDownLis t.SelectedValue +" and " +"
SectionLineMast er.SectionLineD escription = '" +
resouce_TextBox .Text.Trim() +"'" ;
}

if(checkTaluka_ CheckBox.Checke d ==true)
{
if (strcondition.L ength 6)
{
strcondition = strcondition + " AND " ;
}

strcondition = strcondition +"TalukaMaster. "+ "TalukaId ="+
taluka_DropDown List.SelectedVa lue +" and " +"
SectionLineMast er.SectionLineD escription = '" +
resouce_TextBox .Text.Trim() +"'";
}

if(checkCircle_ CheckBox.Checke d ==true)
{
if (strcondition.L ength 6)
{
strcondition = strcondition + " AND " ;
}

strcondition = strcondition +"CircleMaster. "+ "CircleId ="+
circle_DropDown List.SelectedVa lue +" and " +"
SectionLineMast er.SectionLineD escription = '" +
resouce_TextBox .Text.Trim()+"' " ;
}

if(checkVillage _CheckBox.Check ed ==true)
{
if (strcondition.L ength 6)
{
strcondition = strcondition + " AND " ;
}

strcondition = strcondition + "VillageMaster. "+ "VillageId ="+
village_DropDow nList.SelectedV alue +" and " +"
SectionLineMast er.SectionLineD escription = '" +
resouce_TextBox .Text.Trim()+"' " ;
}

DataView dv ;
dv =
VS.DAC.PDMO.Gen eralDesMng.Sear chSectionsLines ByDistrict(strc ondition);

if (dv.Count 0)
{
Label number_Label =
(Label)searchRe sult_DataGrid.F indControl("num Header_Label");
number_Label.Te xt= dv[0]["NumUnit"].ToString();

Label capacity_Label =
(Label)searchRe sult_DataGrid.F indControl("cap Header_Label");
capacity_Label. Text =dv[0]["CapUnit"].ToString();

Label address_Label =
(Label)searchRe sult_DataGrid.F indControl("add rHeader_Label") ;
address_Label.T ext=dv[0]["AddrUnit"].ToString();
}

searchResult_Da taGrid.DataSour ce = dv;
searchResult_Da taGrid.DataBind ();

}
catch(Exception ex)
{
Response.Write( "<script language=Javasc riptalert('"+
ex.Message.ToSt ring()+"') ;</script>");
}
}

Aug 1 '06 #1
1 1316
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.comwr ote in message
news:11******** *************@7 5g2000cwc.googl egroups.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(o bject sender, System.EventArg s e)
{
selectQuery();
}
private void selectQuery()
{
try
{
string strcondition="W HERE ";
if(checkDistric t_CheckBox.Chec ked ==true)
{
strcondition = strcondition + " DistrictMaster. "+ " districtid = "
+ district_DropDo wnList.Selected Value +" and " +"
SectionLineMast er.SectionLineD escription = '" +
resouce_TextBox .Text.Trim() + "' ";
}

if(checkSDO_Che ckBox.Checked ==true)
{
if (strcondition.L ength 6)
{
strcondition = strcondition + " AND " ;
}

strcondition = strcondition + "SDOMaster. "+ " SDOId = " +
SDO_DropDownLis t.SelectedValue +" and " +"
SectionLineMast er.SectionLineD escription = '" +
resouce_TextBox .Text.Trim() +"'" ;
}

if(checkTaluka_ CheckBox.Checke d ==true)
{
if (strcondition.L ength 6)
{
strcondition = strcondition + " AND " ;
}

strcondition = strcondition +"TalukaMaster. "+ "TalukaId ="+
taluka_DropDown List.SelectedVa lue +" and " +"
SectionLineMast er.SectionLineD escription = '" +
resouce_TextBox .Text.Trim() +"'";
}

if(checkCircle_ CheckBox.Checke d ==true)
{
if (strcondition.L ength 6)
{
strcondition = strcondition + " AND " ;
}

strcondition = strcondition +"CircleMaster. "+ "CircleId ="+
circle_DropDown List.SelectedVa lue +" and " +"
SectionLineMast er.SectionLineD escription = '" +
resouce_TextBox .Text.Trim()+"' " ;
}

if(checkVillage _CheckBox.Check ed ==true)
{
if (strcondition.L ength 6)
{
strcondition = strcondition + " AND " ;
}

strcondition = strcondition + "VillageMaster. "+ "VillageId ="+
village_DropDow nList.SelectedV alue +" and " +"
SectionLineMast er.SectionLineD escription = '" +
resouce_TextBox .Text.Trim()+"' " ;
}

DataView dv ;
dv =
VS.DAC.PDMO.Gen eralDesMng.Sear chSectionsLines ByDistrict(strc ondition);

if (dv.Count 0)
{
Label number_Label =
(Label)searchRe sult_DataGrid.F indControl("num Header_Label");
number_Label.Te xt= dv[0]["NumUnit"].ToString();

Label capacity_Label =
(Label)searchRe sult_DataGrid.F indControl("cap Header_Label");
capacity_Label. Text =dv[0]["CapUnit"].ToString();

Label address_Label =
(Label)searchRe sult_DataGrid.F indControl("add rHeader_Label") ;
address_Label.T ext=dv[0]["AddrUnit"].ToString();
}

searchResult_Da taGrid.DataSour ce = dv;
searchResult_Da taGrid.DataBind ();

}
catch(Exception ex)
{
Response.Write( "<script language=Javasc riptalert('"+
ex.Message.ToSt ring()+"') ;</script>");
}
}

Aug 1 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
7902
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 header of the datagrid in the "ItemDataBound" method of the grid. However, once, they are added in the grid, i seem to lose the event handler for the...
2
945
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 datagrid. HTML Datagrid1 TemplateColumn Table Header information Detail Information
1
8902
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 problem is that when you click the added column header it doesn't trigger the sort. The code : <%@ Page language="c#"...
2
3111
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 does not seem to be working.
2
4545
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: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchcreatingwebservercontroltemplatesprogrammatically.asp I have narrowed down the problem comes in when the _DataBinding handler is called and...
0
2397
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 CheckBox Programmatically" in my code. I have changed it to use a OLDDB.DBReader to populate the datagrid and for the databinding. It works perfectly -...
5
1208
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
1817
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 it's a Sharepoint WebPart. I'm trying to do something fairly simple, create a datagrid that displays where and when a person works and allows them to...
4
2005
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, when the datagrid enters it's own OnPreRender, the selected index has reverted to zero. I created a debug version of the dropdown list which...
0
8202
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8216
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.