473,725 Members | 2,422 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 1322
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
7928
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 same control. Is there anyone who has tried this before and knows why this is hapenning ??
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
8907
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#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
2
3117
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
4552
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 the literal text is being assigned, but I can't figure out beyond that. The main problem is that...
0
2403
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 - also when using the edit-mode in the datagrid.
5
1211
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
1831
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 change some of the information via DropDownLists. When the user clicks to edit a row, three of...
4
2011
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 inherited from dropdownlist and overrode the selected index property to trace.write whenever it was...
0
8878
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9250
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9165
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9097
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6699
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6006
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4507
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2626
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2153
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.