G
Guest
I am trying to get the text of an item in a GridView, but am doing something
wrong. Can someone help me with the correct C# statement I need? Below is my
GridView and my attempt to get the control. Thank you.
string option =
((TextBox)dgDropDownMenus.Items[e.Item.ItemIndex].FindControl("txtName")).Text;
-----------------------DataGrid-------------------------------------------
<asp:datagrid id="dgMenus" style="Z-INDEX: 101; LEFT: 0px; POSITION:
absolute; TOP: 0px"
runat="server" DataKeyField="DropDownMenuID" CellPadding="0"
BackColor="White" BorderStyle="None" Font-Bold="True" BorderWidth="1px"
BorderColor="#999999" GridLines="Vertical" HorizontalAlign="Center"
AutoGenerateColumns="False" Width="100%">
<FooterStyle ForeColor="Black" BackColor="#CCCCCC"></FooterStyle>
<SelectedItemStyle Font-Bold="True" HorizontalAlign="Center"
Height="10px" ForeColor="White" VerticalAlign="Middle"
BackColor="#008A8C"></SelectedItemStyle>
<EditItemStyle HorizontalAlign="Center" Height="10px" Width="50px"
VerticalAlign="Middle"></EditItemStyle>
<AlternatingItemStyle HorizontalAlign="Center" Height="10px"
VerticalAlign="Middle" BackColor="Gainsboro"></AlternatingItemStyle>
<ItemStyle HorizontalAlign="Center" Height="10px" ForeColor="Black"
VerticalAlign="Middle"
BackColor="White"></ItemStyle>
<HeaderStyle Wrap="False" CssClass="datagridheader"></HeaderStyle>
<Columns>
<asp:ButtonColumn Text="<img border="0" src="../images/edit_icon.gif">"
HeaderText="Edit" CommandName="Edit">
<HeaderStyle HorizontalAlign="Center" Width="5%"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:ButtonColumn>
<asp:TemplateColumn HeaderText="Name">
<HeaderStyle Width="25px"></HeaderStyle>
<ItemTemplate>
<asp:Label id="lblName" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.DisplayName") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtName" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.DisplayName") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Description">
<HeaderStyle Width="70%"></HeaderStyle>
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.Description") %>' ID="Label2">
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="Textbox1" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.Description") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle VerticalAlign="Middle" NextPageText="Next -->"
PrevPageText="<-- Previous"
HorizontalAlign="Center" ForeColor="Black" BackColor="#999999"
Wrap="False" Mode="NumericPages"></PagerStyle>
</asp:datagrid>
wrong. Can someone help me with the correct C# statement I need? Below is my
GridView and my attempt to get the control. Thank you.
string option =
((TextBox)dgDropDownMenus.Items[e.Item.ItemIndex].FindControl("txtName")).Text;
-----------------------DataGrid-------------------------------------------
<asp:datagrid id="dgMenus" style="Z-INDEX: 101; LEFT: 0px; POSITION:
absolute; TOP: 0px"
runat="server" DataKeyField="DropDownMenuID" CellPadding="0"
BackColor="White" BorderStyle="None" Font-Bold="True" BorderWidth="1px"
BorderColor="#999999" GridLines="Vertical" HorizontalAlign="Center"
AutoGenerateColumns="False" Width="100%">
<FooterStyle ForeColor="Black" BackColor="#CCCCCC"></FooterStyle>
<SelectedItemStyle Font-Bold="True" HorizontalAlign="Center"
Height="10px" ForeColor="White" VerticalAlign="Middle"
BackColor="#008A8C"></SelectedItemStyle>
<EditItemStyle HorizontalAlign="Center" Height="10px" Width="50px"
VerticalAlign="Middle"></EditItemStyle>
<AlternatingItemStyle HorizontalAlign="Center" Height="10px"
VerticalAlign="Middle" BackColor="Gainsboro"></AlternatingItemStyle>
<ItemStyle HorizontalAlign="Center" Height="10px" ForeColor="Black"
VerticalAlign="Middle"
BackColor="White"></ItemStyle>
<HeaderStyle Wrap="False" CssClass="datagridheader"></HeaderStyle>
<Columns>
<asp:ButtonColumn Text="<img border="0" src="../images/edit_icon.gif">"
HeaderText="Edit" CommandName="Edit">
<HeaderStyle HorizontalAlign="Center" Width="5%"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:ButtonColumn>
<asp:TemplateColumn HeaderText="Name">
<HeaderStyle Width="25px"></HeaderStyle>
<ItemTemplate>
<asp:Label id="lblName" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.DisplayName") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtName" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.DisplayName") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Description">
<HeaderStyle Width="70%"></HeaderStyle>
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.Description") %>' ID="Label2">
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="Textbox1" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.Description") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle VerticalAlign="Middle" NextPageText="Next -->"
PrevPageText="<-- Previous"
HorizontalAlign="Center" ForeColor="Black" BackColor="#999999"
Wrap="False" Mode="NumericPages"></PagerStyle>
</asp:datagrid>