473,804 Members | 2,140 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to access Datagrid Linkbutton with OnItemDataBound ?

I keep getting this error when trying to modify the text property of a
linkbutton inside a datagrid template column.

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.NullRefe renceException: Object reference not
set to an instance of an object.

Source Error:


Line 234: b.Text="Replace with this item"; // ERROR HAPPENS HERE

Line 235:

Line 236: for (int i=0; i < (e.Item.Cells.C ount)-1; i++)



// CODE

public void CheckRow(object sender, DataGridItemEve ntArgs e)

{

string keyword = Request.QuerySt ring["keyword"];

if (keyword!=null && keyword!=null) // Replace item event happens
(uses button Replace this item)

{

// changes button label

string test= e.Item.Cells.Co unt.ToString();

//gets first template column. It needs to be accessed differently
from databound items

LinkButton b = (LinkButton)e.I tem.FindControl ("btAddReplace" );

b.Text="Replace with this item";

for (int i=0; i < (e.Item.Cells.C ount)-1; i++)

{

Response.Write( i.ToString()+e. Item.Cells[i].Text+"<br>");

}

}

}


I also tried these two other alternatives and no success:
LinkButton b = (LinkButton)e.I tem.Cells[0].Controls[0];

DataBoundLitera lControl b = b.Controls[0] as
DataBoundLitera lControl;


The error only happens when I try to access the control property
"b.Text". The instance of it is recognized by the framework.
thank you

Rod

Nov 16 '05 #1
1 3537
I've just figured out. I forgot to skip the Datagrid headers

if (e.Item.ItemTyp e == ListItemType.Se lectedItem || e.Item.ItemType
== ListItemType.It em || e.Item.ItemType ==
ListItemType.Al ternatingItem)
{
code here
}

Rod

Nov 16 '05 #2

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

Similar topics

9
5068
by: tshad | last post by:
How do I find (and set) a couple of labels in the Footer after a DataGrid is filled? I have a bunch of DataGrids that get displayed nested inside a DataList. The datagrid looks like: ******************************************************************************* <asp:DataGrid visible="False" border=1
4
3499
by: tshad | last post by:
I am having trouble with links in my DataGrid. I have Links all over my page set to smaller and they are consistant all over the page in both Mozilla and IE, except for the DataGrid. Here is a snippet from my .css file: *************************** body { margin:0; padding:0;
16
1682
by: tshad | last post by:
I am trying to center a button in a datagrid column in asp.net and it doesn't seem to work. I have the following: <asp:TemplateColumn ItemStyle-Width="10%" ItemStyle-HorizontalAlign="Center"> <FooterTemplate> <asp:LinkButton CommandName="Insert" Text="<img src='..\images\Add.gif'border='0'>" ID="btnAdd" Runat="server" />
1
1010
by: Tim::.. | last post by:
Can someone please tell me how I turn an ItemTemplate into a link? I don't what to use a HyperlinkColumn as I have two lines in one column in the datagrid coming from different sources! I would like to turn the top time into a link! EG:Have <%# Container.DataItem("header")%> as a link <a href="default.aspx?id= <%# Container.DataItem("itemID")%>"><%# Container.DataItem("header")%> </a>
6
2193
by: tshad | last post by:
I have a datagrid where each column has both a label and a linkbutton. I need to have the label left justified and the linkbutton right justified. In HTML, I would have to set up 2 cells to do this. Is there a way to accomplish this in a DataGrid (and have the text span both columns). What I have is:
2
1494
by: Frank | last post by:
Hello, I am developing with VS.Net 2003 on the asp 1.1 platform. I am a few days new to using a datagrid. I found a nice tutorial and had no problems using an editable datagrid with textboxes and an additional buttoncolumn where I used a delete button to delete a specific row. Once I had finished that, I trnsformed the grid tso it will display a dropdownlist indtead of a textbox. After much grappling, I pretty much have
0
1414
by: rockdale | last post by:
Hi, All: I dynamic add an arrow up/down image in OnItemDataBound event for my datagrid, it works fine. But I have another textbox which trigger postback and doing something, after this event get executed, I lost the image but the datagrid maintain the same sort order. Should the datagrid remain what it looks like (with the riget arrow up/down image) before the postback caused by the textbox?
2
7215
by: Hardy Wang | last post by:
Hi all, We have DataGrid control in Web Form, our client requires to be able to click anywhere of a row to fire the event same as LinkBotton column is clicked. We we did in ASP.NET 1.1 is in ASPX page <asp:DataGrid id="MyGrid" runat="server" AutoGenerateColumns="False" AllowSorting="True" AllowPaging="True" runat="server" EnableViewState="True"> <Columns>
2
1674
by: tshad | last post by:
I am having a problem with my Datagrid that displays my Files via GetFiles() If I use a HyperLinkColumn - I can use the column name "Name" which is what the result from GetFiles(). ******************************************************** Sub GetFileList() Dim dirInfo as DirectoryInfo = new DirectoryInfo(Server.MapPath("/uploads/"))
0
9595
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10353
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
10356
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
10099
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
7643
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
5536
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...
1
4314
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3836
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3003
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.