473,387 Members | 3,750 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,387 software developers and data experts.

Doesn't find grid control

47
Can someone help? I have the code below in which I'm attempting to show or hide the edit control in a gridview based on the value of a column in that view. It doesn't seem to find the control. I've included the RowDataBound event as well as the gridview definition. Thanks in advance.
Expand|Select|Wrap|Line Numbers
  1. protected void gvEmployeesBenefits_RowDataBound(object sender, GridViewRowEventArgs e)
  2.     {
  3.         TextBox EditFlg = (TextBox) e.Row.FindControl("txtEditflg");
  4.         if (EditFlg.Text == "1")
  5.         {
  6.             LinkButton MyLinkButton = (LinkButton)e.Row.FindControl("lnkEdit");
  7.             MyLinkButton.Visible = true;
  8.         }
  9.         else
  10.         {
  11.             LinkButton MyLinkButton = (LinkButton)e.Row.FindControl("lnkEdit");
  12.             MyLinkButton.Visible = false;
  13.         }
  14.  
  15.     }
Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="gvEmployeesBenefits" runat="server" DataSourceID="Benefits" Style="z-index: 100;
  2.     left: 0px; top: 0px" AutoGenerateColumns="False" BackColor="White" 
  3.     BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" 
  4.     GridLines="Horizontal" onrowdatabound="gvEmployeesBenefits_RowDataBound" 
  5.     CellSpacing="3" HorizontalAlign="Justify">
  6.     <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
  7.     <Columns>
  8.         <asp:TemplateField ShowHeader="False">
  9.             <EditItemTemplate>
  10.                 <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" 
  11.                     CommandName="Update" Text="Update"></asp:LinkButton>
  12.                 &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
  13.                     CommandName="Cancel" Text="Cancel"></asp:LinkButton>
  14.             </EditItemTemplate>
  15.             <ItemTemplate>
  16.                 <asp:LinkButton ID="lnkEdit" runat="server" CausesValidation="False" 
  17.                     CommandName="Edit" Text="Edit"></asp:LinkButton>
  18.             </ItemTemplate>
  19.         </asp:TemplateField>
  20.         <asp:BoundField DataField="BGAN8" HeaderText="Emp#" 
  21.             ReadOnly="True" Visible="False" />
  22.         <asp:BoundField DataField="BGPLAN" HeaderText="Plan" ReadOnly="True" 
  23.             Visible="False" />
  24.         <asp:BoundField DataField="BGAOPT" HeaderText="Option" ReadOnly="True" 
  25.             Visible="False" />
  26.         <asp:BoundField DataField="BAEXA" HeaderText="Plan Description" 
  27.             ReadOnly="True" />
  28.         <asp:BoundField DataField="BGEFT" HeaderText="Enrollment Date" 
  29.             ReadOnly="True" />
  30.         <asp:BoundField DataField="BAFDBA" HeaderText="BAFDBA" ReadOnly="True" 
  31.             Visible="False" />
  32.         <asp:BoundField DataField="BASDBA" HeaderText="BASDBA" ReadOnly="True" 
  33.             Visible="False" />
  34.         <asp:BoundField AccessibleHeaderText="RT" DataField="RT" 
  35.             DataFormatString="{0:N2}" HeaderText="RT" />
  36.         <asp:BoundField DataField="YTD" DataFormatString="{0:N2}" HeaderText="YTD" 
  37.             ReadOnly="True" />
  38.         <asp:HyperLinkField HeaderText="Website" DataNavigateUrlFields="Website" 
  39.             DataTextField="Website" Target="_blank" 
  40.            />
  41.         <asp:HyperLinkField 
  42.             HeaderText="Forms" Target="_blank" Text='<% Eval("Forms") %>' />
  43.         <asp:TemplateField HeaderText="EditFlg">
  44.             <EditItemTemplate>
  45.                 <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Editflg") %>'></asp:TextBox>
  46.             </EditItemTemplate>
  47.             <ItemTemplate>
  48.                 <asp:Label ID="txtEditFlg" runat="server" Text='<%# Bind("Editflg") %>'></asp:Label>
  49.             </ItemTemplate>
  50.         </asp:TemplateField>
  51.     </Columns>
  52.     <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
  53.     <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
  54.     <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
  55.     <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
  56.     <EditRowStyle HorizontalAlign="Right" VerticalAlign="Middle" Wrap="False" />
  57.     <AlternatingRowStyle BackColor="#F7F7F7" />
  58. </asp:GridView>
May 7 '09 #1
3 2020
@kimbred
Not sure if this is it, but you declared your variable of type TextBox when the control you're finding is a Label
May 8 '09 #2
kimbred
47
That was it. Thanks. Not sure the Row Data Bound event is the correct place to put this though. When I select the edit link on the row, all rows magically get the edit link. Thanks again.
May 8 '09 #3
This is probably what you want (in the rowdatabound event)

Expand|Select|Wrap|Line Numbers
  1. If e.Row.RowType = DataControlRowType.DataRow Then
  2.     If e.Row.DataItem("Editflg") = "1" Then
  3.          e.Row.RowState = DataControlRowState.Edit
  4.     Else
  5.          e.Row.RowState = DataControlRowState.Normal
  6.     End If
  7. End If
  8.  
Using the c# equivalent ofcourse.
May 8 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

44
by: Mariusz Jedrzejewski | last post by:
Hi, I'll be very grateful if somebody can explain me why my Opera 7.23 (runing under linux) doesn't show me inner tables. Using below code I can see only "inner table 1". There is no problem with...
6
by: Kate | last post by:
Hi, we are now developing complex business application using Ajax framework. Could anyone point me to the editable javascript grid control which supports XML loading. Good javascript API would be...
12
by: Jim H | last post by:
We ahve a .NET web page that we dynamically create a bunch of DataGrids and add them to a place holder. When the user hits submit we need to go through all of the DataGrids to get some data. We...
5
by: David Freeman | last post by:
Hi There! I'm using ASP.NET 1.1 and VB. Below is my DataGrid declaration... <asp:DataGrid id="myDataGrid" runat="server" AutoGenerateColumns="false"
2
by: Tom | last post by:
I need to display a series of controls (in my case, a custom control) in a grid-like fashion. This means this particular control would be repeated multiple times, arranged in a row/column format....
7
by: Peter Proost | last post by:
Hi group, Here at work they've got an activeX control which is used on a usercontrol, and this usercontrol is one of the standard controls in the framework, so this user controls get's used a...
7
by: JohnR | last post by:
I am using dragdrop to drag and drop a custom class instance. When I drag/drop from one window to another window in the same application everything works fine. But when trying to move between the...
0
by: LeAnne | last post by:
In my ASPX page, I populate the GRID when the user selects an item in the dropdown list. Thus, the data is fetched and the data grid DataBind() method is executed in the PostBack (i.e. IsPostBack...
1
by: nipe | last post by:
Hello, I'm having problem with my custom datagrid control can't fire itemcommand event. The fact is that I have to make fully cutom user control so I can't do any scripting to .aspx file. There...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
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...

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.