Trying to use FindControl

Discussion in 'ASP .Net' started by =?Utf-8?B?TWlrZSBDb2xsaW5z?=, Dec 22, 2006.

  1. 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>
     
    =?Utf-8?B?TWlrZSBDb2xsaW5z?=, Dec 22, 2006
    #1
    1. Advertising

  2. Hi,
    It should be:
    DataGrid dgDropDownMenus= (DataGrid)sender;
    if(e.Item.ItemType.ToString() != "Header" && e.Item.ItemType.ToString() !=
    "Footer")
    {
    string option = ((TextBox )e.Item.FindControl("txtName")).Text;
    }

    Although i have written this code for Datagrid, you can use same for
    gridview with little or no modification.
    Thanks and Regards,
    Manish Bafna.
    MCP and MCTS.

    "Mike Collins" wrote:

    > 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>
    >
    >
     
    =?Utf-8?B?TWFuaXNoIEJhZm5h?=, Dec 23, 2006
    #2
    1. Advertising

  3. Thanks, but I get an error: Object reference not set to an instance of an
    object. Any idea on why that is happening?

    "Manish Bafna" wrote:

    > Hi,
    > It should be:
    > DataGrid dgDropDownMenus= (DataGrid)sender;
    > if(e.Item.ItemType.ToString() != "Header" && e.Item.ItemType.ToString() !=
    > "Footer")
    > {
    > string option = ((TextBox )e.Item.FindControl("txtName")).Text;
    > }
    >
    > Although i have written this code for Datagrid, you can use same for
    > gridview with little or no modification.
    > Thanks and Regards,
    > Manish Bafna.
    > MCP and MCTS.
    >
    > "Mike Collins" wrote:
    >
    > > 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>
    > >
    > >
     
    =?Utf-8?B?TWlrZSBDb2xsaW5z?=, Dec 23, 2006
    #3
  4. Hi,
    can you please tell at which line you are getting this error?Most probably
    you would be using this line of findcontrol in update event of DataGrid.If
    you give details as to where r using this code of findcontrol or in which
    event u r using then only i would be able to help you out.

    Thanks and Regards,
    Manish Bafna.
    MCP and MCTS.

    "Mike Collins" wrote:

    > Thanks, but I get an error: Object reference not set to an instance of an
    > object. Any idea on why that is happening?
    >
    > "Manish Bafna" wrote:
    >
    > > Hi,
    > > It should be:
    > > DataGrid dgDropDownMenus= (DataGrid)sender;
    > > if(e.Item.ItemType.ToString() != "Header" && e.Item.ItemType.ToString() !=
    > > "Footer")
    > > {
    > > string option = ((TextBox )e.Item.FindControl("txtName")).Text;
    > > }
    > >
    > > Although i have written this code for Datagrid, you can use same for
    > > gridview with little or no modification.
    > > Thanks and Regards,
    > > Manish Bafna.
    > > MCP and MCTS.
    > >
    > > "Mike Collins" wrote:
    > >
    > > > 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>
    > > >
    > > >
     
    =?Utf-8?B?TWFuaXNoIEJhZm5h?=, Dec 23, 2006
    #4
  5. Sorry for the incomplete response. Below is the event that is running, and I
    am getting an error on the first line of the method "string option..."

    private void dgDropDownMenus_EditCommand(object source,
    System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    string option = ((TextBox)e.Item.FindControl("txtName")).Text;
    Server.Transfer("../surveys/manageansweroptions.aspx?AnswerGroupID=" +
    dgDropDownMenus.DataKeys[e.Item.ItemIndex].ToString() + "&CallingPage=Manage
    Dropdowns Page&ReturnURL=ManageDropDowns.aspx&option=" +
    rblOption.SelectedItem.Value + "&GroupName=" +
    dgDropDownMenus.Items[e.Item.ItemIndex].Cells[2].Text);
    }


    "Manish Bafna" wrote:

    > Hi,
    > can you please tell at which line you are getting this error?Most probably
    > you would be using this line of findcontrol in update event of DataGrid.If
    > you give details as to where r using this code of findcontrol or in which
    > event u r using then only i would be able to help you out.
    >
    > Thanks and Regards,
    > Manish Bafna.
    > MCP and MCTS.
    >
    > "Mike Collins" wrote:
    >
    > > Thanks, but I get an error: Object reference not set to an instance of an
    > > object. Any idea on why that is happening?
    > >
    > > "Manish Bafna" wrote:
    > >
    > > > Hi,
    > > > It should be:
    > > > DataGrid dgDropDownMenus= (DataGrid)sender;
    > > > if(e.Item.ItemType.ToString() != "Header" && e.Item.ItemType.ToString() !=
    > > > "Footer")
    > > > {
    > > > string option = ((TextBox )e.Item.FindControl("txtName")).Text;
    > > > }
    > > >
    > > > Although i have written this code for Datagrid, you can use same for
    > > > gridview with little or no modification.
    > > > Thanks and Regards,
    > > > Manish Bafna.
    > > > MCP and MCTS.
    > > >
    > > > "Mike Collins" wrote:
    > > >
    > > > > 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>
    > > > >
    > > > >
     
    =?Utf-8?B?TWlrZSBDb2xsaW5z?=, Dec 23, 2006
    #5
  6. Hi,
    Try this one:
    this.dgMenus.EditItemIndex = e.Item.ItemIndex;
    dgMenus.Items[this.DataGrid1.EditItemIndex].FindControl("txtName") as TextBox

    Thanks and Regards,
    Manish Bafna.
    MCP and MCTS.


    "Mike Collins" wrote:

    > Sorry for the incomplete response. Below is the event that is running, and I
    > am getting an error on the first line of the method "string option..."
    >
    > private void dgDropDownMenus_EditCommand(object source,
    > System.Web.UI.WebControls.DataGridCommandEventArgs e)
    > {
    > string option = ((TextBox)e.Item.FindControl("txtName")).Text;
    > Server.Transfer("../surveys/manageansweroptions.aspx?AnswerGroupID=" +
    > dgDropDownMenus.DataKeys[e.Item.ItemIndex].ToString() + "&CallingPage=Manage
    > Dropdowns Page&ReturnURL=ManageDropDowns.aspx&option=" +
    > rblOption.SelectedItem.Value + "&GroupName=" +
    > dgDropDownMenus.Items[e.Item.ItemIndex].Cells[2].Text);
    > }
    >
    >
    > "Manish Bafna" wrote:
    >
    > > Hi,
    > > can you please tell at which line you are getting this error?Most probably
    > > you would be using this line of findcontrol in update event of DataGrid.If
    > > you give details as to where r using this code of findcontrol or in which
    > > event u r using then only i would be able to help you out.
    > >
    > > Thanks and Regards,
    > > Manish Bafna.
    > > MCP and MCTS.
    > >
    > > "Mike Collins" wrote:
    > >
    > > > Thanks, but I get an error: Object reference not set to an instance of an
    > > > object. Any idea on why that is happening?
    > > >
    > > > "Manish Bafna" wrote:
    > > >
    > > > > Hi,
    > > > > It should be:
    > > > > DataGrid dgDropDownMenus= (DataGrid)sender;
    > > > > if(e.Item.ItemType.ToString() != "Header" && e.Item.ItemType.ToString() !=
    > > > > "Footer")
    > > > > {
    > > > > string option = ((TextBox )e.Item.FindControl("txtName")).Text;
    > > > > }
    > > > >
    > > > > Although i have written this code for Datagrid, you can use same for
    > > > > gridview with little or no modification.
    > > > > Thanks and Regards,
    > > > > Manish Bafna.
    > > > > MCP and MCTS.
    > > > >
    > > > > "Mike Collins" wrote:
    > > > >
    > > > > > 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>
    > > > > >
    > > > > >
     
    =?Utf-8?B?TWFuaXNoIEJhZm5h?=, Dec 23, 2006
    #6
  7. I had to change your code where you had the "as TextBox" because it caused an
    error to the following:

    this.dgDropDownMenus.EditItemIndex = e.Item.ItemIndex;
    TextBox option =
    (TextBox)dgDropDownMenus.Items[this.dgDropDownMenus.EditItemIndex].FindControl("txtName");

    Then I got the following error: error: identifier 'option' out of scope,
    when I checked the object "option" after running the code. It was not a run
    time error, I did a quick watch.

    I appreciate your patience and help in trying to help me figure this out.

    "Manish Bafna" wrote:

    > Hi,
    > Try this one:
    > this.dgMenus.EditItemIndex = e.Item.ItemIndex;
    > dgMenus.Items[this.DataGrid1.EditItemIndex].FindControl("txtName") as TextBox
    >
    > Thanks and Regards,
    > Manish Bafna.
    > MCP and MCTS.
    >
    >
    > "Mike Collins" wrote:
    >
    > > Sorry for the incomplete response. Below is the event that is running, and I
    > > am getting an error on the first line of the method "string option..."
    > >
    > > private void dgDropDownMenus_EditCommand(object source,
    > > System.Web.UI.WebControls.DataGridCommandEventArgs e)
    > > {
    > > string option = ((TextBox)e.Item.FindControl("txtName")).Text;
    > > Server.Transfer("../surveys/manageansweroptions.aspx?AnswerGroupID=" +
    > > dgDropDownMenus.DataKeys[e.Item.ItemIndex].ToString() + "&CallingPage=Manage
    > > Dropdowns Page&ReturnURL=ManageDropDowns.aspx&option=" +
    > > rblOption.SelectedItem.Value + "&GroupName=" +
    > > dgDropDownMenus.Items[e.Item.ItemIndex].Cells[2].Text);
    > > }
    > >
    > >
    > > "Manish Bafna" wrote:
    > >
    > > > Hi,
    > > > can you please tell at which line you are getting this error?Most probably
    > > > you would be using this line of findcontrol in update event of DataGrid.If
    > > > you give details as to where r using this code of findcontrol or in which
    > > > event u r using then only i would be able to help you out.
    > > >
    > > > Thanks and Regards,
    > > > Manish Bafna.
    > > > MCP and MCTS.
    > > >
    > > > "Mike Collins" wrote:
    > > >
    > > > > Thanks, but I get an error: Object reference not set to an instance of an
    > > > > object. Any idea on why that is happening?
    > > > >
    > > > > "Manish Bafna" wrote:
    > > > >
    > > > > > Hi,
    > > > > > It should be:
    > > > > > DataGrid dgDropDownMenus= (DataGrid)sender;
    > > > > > if(e.Item.ItemType.ToString() != "Header" && e.Item.ItemType.ToString() !=
    > > > > > "Footer")
    > > > > > {
    > > > > > string option = ((TextBox )e.Item.FindControl("txtName")).Text;
    > > > > > }
    > > > > >
    > > > > > Although i have written this code for Datagrid, you can use same for
    > > > > > gridview with little or no modification.
    > > > > > Thanks and Regards,
    > > > > > Manish Bafna.
    > > > > > MCP and MCTS.
    > > > > >
    > > > > > "Mike Collins" wrote:
    > > > > >
    > > > > > > 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>
    > > > > > >
    > > > > > >
     
    =?Utf-8?B?TWlrZSBDb2xsaW5z?=, Dec 23, 2006
    #7
  8. Hi,
    so finally it was solved or you r still getting some errors?

    "Mike Collins" wrote:

    > I had to change your code where you had the "as TextBox" because it caused an
    > error to the following:
    >
    > this.dgDropDownMenus.EditItemIndex = e.Item.ItemIndex;
    > TextBox option =
    > (TextBox)dgDropDownMenus.Items[this.dgDropDownMenus.EditItemIndex].FindControl("txtName");
    >
    > Then I got the following error: error: identifier 'option' out of scope,
    > when I checked the object "option" after running the code. It was not a run
    > time error, I did a quick watch.
    >
    > I appreciate your patience and help in trying to help me figure this out.
    >
    > "Manish Bafna" wrote:
    >
    > > Hi,
    > > Try this one:
    > > this.dgMenus.EditItemIndex = e.Item.ItemIndex;
    > > dgMenus.Items[this.DataGrid1.EditItemIndex].FindControl("txtName") as TextBox
    > >
    > > Thanks and Regards,
    > > Manish Bafna.
    > > MCP and MCTS.
    > >
    > >
    > > "Mike Collins" wrote:
    > >
    > > > Sorry for the incomplete response. Below is the event that is running, and I
    > > > am getting an error on the first line of the method "string option..."
    > > >
    > > > private void dgDropDownMenus_EditCommand(object source,
    > > > System.Web.UI.WebControls.DataGridCommandEventArgs e)
    > > > {
    > > > string option = ((TextBox)e.Item.FindControl("txtName")).Text;
    > > > Server.Transfer("../surveys/manageansweroptions.aspx?AnswerGroupID=" +
    > > > dgDropDownMenus.DataKeys[e.Item.ItemIndex].ToString() + "&CallingPage=Manage
    > > > Dropdowns Page&ReturnURL=ManageDropDowns.aspx&option=" +
    > > > rblOption.SelectedItem.Value + "&GroupName=" +
    > > > dgDropDownMenus.Items[e.Item.ItemIndex].Cells[2].Text);
    > > > }
    > > >
    > > >
    > > > "Manish Bafna" wrote:
    > > >
    > > > > Hi,
    > > > > can you please tell at which line you are getting this error?Most probably
    > > > > you would be using this line of findcontrol in update event of DataGrid.If
    > > > > you give details as to where r using this code of findcontrol or in which
    > > > > event u r using then only i would be able to help you out.
    > > > >
    > > > > Thanks and Regards,
    > > > > Manish Bafna.
    > > > > MCP and MCTS.
    > > > >
    > > > > "Mike Collins" wrote:
    > > > >
    > > > > > Thanks, but I get an error: Object reference not set to an instance of an
    > > > > > object. Any idea on why that is happening?
    > > > > >
    > > > > > "Manish Bafna" wrote:
    > > > > >
    > > > > > > Hi,
    > > > > > > It should be:
    > > > > > > DataGrid dgDropDownMenus= (DataGrid)sender;
    > > > > > > if(e.Item.ItemType.ToString() != "Header" && e.Item.ItemType.ToString() !=
    > > > > > > "Footer")
    > > > > > > {
    > > > > > > string option = ((TextBox )e.Item.FindControl("txtName")).Text;
    > > > > > > }
    > > > > > >
    > > > > > > Although i have written this code for Datagrid, you can use same for
    > > > > > > gridview with little or no modification.
    > > > > > > Thanks and Regards,
    > > > > > > Manish Bafna.
    > > > > > > MCP and MCTS.
    > > > > > >
    > > > > > > "Mike Collins" wrote:
    > > > > > >
    > > > > > > > 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>
    > > > > > > >
    > > > > > > >
     
    =?Utf-8?B?TWFuaXNoIEJhZm5h?=, Dec 23, 2006
    #8
  9. Still an error.

    error: identifier 'option' out of scope, when I checked the object "option"
    after running the code. It was not a run time error, I did a quick watch and
    saw it.

    "Manish Bafna" wrote:

    > Hi,
    > so finally it was solved or you r still getting some errors?
    >
    > "Mike Collins" wrote:
    >
    > > I had to change your code where you had the "as TextBox" because it caused an
    > > error to the following:
    > >
    > > this.dgDropDownMenus.EditItemIndex = e.Item.ItemIndex;
    > > TextBox option =
    > > (TextBox)dgDropDownMenus.Items[this.dgDropDownMenus.EditItemIndex].FindControl("txtName");
    > >
    > > Then I got the following error: error: identifier 'option' out of scope,
    > > when I checked the object "option" after running the code. It was not a run
    > > time error, I did a quick watch.
    > >
    > > I appreciate your patience and help in trying to help me figure this out.
    > >
    > > "Manish Bafna" wrote:
    > >
    > > > Hi,
    > > > Try this one:
    > > > this.dgMenus.EditItemIndex = e.Item.ItemIndex;
    > > > dgMenus.Items[this.DataGrid1.EditItemIndex].FindControl("txtName") as TextBox
    > > >
    > > > Thanks and Regards,
    > > > Manish Bafna.
    > > > MCP and MCTS.
    > > >
    > > >
    > > > "Mike Collins" wrote:
    > > >
    > > > > Sorry for the incomplete response. Below is the event that is running, and I
    > > > > am getting an error on the first line of the method "string option..."
    > > > >
    > > > > private void dgDropDownMenus_EditCommand(object source,
    > > > > System.Web.UI.WebControls.DataGridCommandEventArgs e)
    > > > > {
    > > > > string option = ((TextBox)e.Item.FindControl("txtName")).Text;
    > > > > Server.Transfer("../surveys/manageansweroptions.aspx?AnswerGroupID=" +
    > > > > dgDropDownMenus.DataKeys[e.Item.ItemIndex].ToString() + "&CallingPage=Manage
    > > > > Dropdowns Page&ReturnURL=ManageDropDowns.aspx&option=" +
    > > > > rblOption.SelectedItem.Value + "&GroupName=" +
    > > > > dgDropDownMenus.Items[e.Item.ItemIndex].Cells[2].Text);
    > > > > }
    > > > >
    > > > >
    > > > > "Manish Bafna" wrote:
    > > > >
    > > > > > Hi,
    > > > > > can you please tell at which line you are getting this error?Most probably
    > > > > > you would be using this line of findcontrol in update event of DataGrid.If
    > > > > > you give details as to where r using this code of findcontrol or in which
    > > > > > event u r using then only i would be able to help you out.
    > > > > >
    > > > > > Thanks and Regards,
    > > > > > Manish Bafna.
    > > > > > MCP and MCTS.
    > > > > >
    > > > > > "Mike Collins" wrote:
    > > > > >
    > > > > > > Thanks, but I get an error: Object reference not set to an instance of an
    > > > > > > object. Any idea on why that is happening?
    > > > > > >
    > > > > > > "Manish Bafna" wrote:
    > > > > > >
    > > > > > > > Hi,
    > > > > > > > It should be:
    > > > > > > > DataGrid dgDropDownMenus= (DataGrid)sender;
    > > > > > > > if(e.Item.ItemType.ToString() != "Header" && e.Item.ItemType.ToString() !=
    > > > > > > > "Footer")
    > > > > > > > {
    > > > > > > > string option = ((TextBox )e.Item.FindControl("txtName")).Text;
    > > > > > > > }
    > > > > > > >
    > > > > > > > Although i have written this code for Datagrid, you can use same for
    > > > > > > > gridview with little or no modification.
    > > > > > > > Thanks and Regards,
    > > > > > > > Manish Bafna.
    > > > > > > > MCP and MCTS.
    > > > > > > >
    > > > > > > > "Mike Collins" wrote:
    > > > > > > >
    > > > > > > > > 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>
    > > > > > > > >
    > > > > > > > >
     
    =?Utf-8?B?TWlrZSBDb2xsaW5z?=, Dec 23, 2006
    #9
  10. Hi,
    I think the error u r getting in quick watch is the bug in the microsoft
    product.See below link:
    http://www.kbalertz.com/Feedback_814828.aspx
    I think you r now able to get text of textbox in datagrid.


    "Mike Collins" wrote:

    > Still an error.
    >
    > error: identifier 'option' out of scope, when I checked the object "option"
    > after running the code. It was not a run time error, I did a quick watch and
    > saw it.
    >
    > "Manish Bafna" wrote:
    >
    > > Hi,
    > > so finally it was solved or you r still getting some errors?
    > >
    > > "Mike Collins" wrote:
    > >
    > > > I had to change your code where you had the "as TextBox" because it caused an
    > > > error to the following:
    > > >
    > > > this.dgDropDownMenus.EditItemIndex = e.Item.ItemIndex;
    > > > TextBox option =
    > > > (TextBox)dgDropDownMenus.Items[this.dgDropDownMenus.EditItemIndex].FindControl("txtName");
    > > >
    > > > Then I got the following error: error: identifier 'option' out of scope,
    > > > when I checked the object "option" after running the code. It was not a run
    > > > time error, I did a quick watch.
    > > >
    > > > I appreciate your patience and help in trying to help me figure this out.
    > > >
    > > > "Manish Bafna" wrote:
    > > >
    > > > > Hi,
    > > > > Try this one:
    > > > > this.dgMenus.EditItemIndex = e.Item.ItemIndex;
    > > > > dgMenus.Items[this.DataGrid1.EditItemIndex].FindControl("txtName") as TextBox
    > > > >
    > > > > Thanks and Regards,
    > > > > Manish Bafna.
    > > > > MCP and MCTS.
    > > > >
    > > > >
    > > > > "Mike Collins" wrote:
    > > > >
    > > > > > Sorry for the incomplete response. Below is the event that is running, and I
    > > > > > am getting an error on the first line of the method "string option..."
    > > > > >
    > > > > > private void dgDropDownMenus_EditCommand(object source,
    > > > > > System.Web.UI.WebControls.DataGridCommandEventArgs e)
    > > > > > {
    > > > > > string option = ((TextBox)e.Item.FindControl("txtName")).Text;
    > > > > > Server.Transfer("../surveys/manageansweroptions.aspx?AnswerGroupID=" +
    > > > > > dgDropDownMenus.DataKeys[e.Item.ItemIndex].ToString() + "&CallingPage=Manage
    > > > > > Dropdowns Page&ReturnURL=ManageDropDowns.aspx&option=" +
    > > > > > rblOption.SelectedItem.Value + "&GroupName=" +
    > > > > > dgDropDownMenus.Items[e.Item.ItemIndex].Cells[2].Text);
    > > > > > }
    > > > > >
    > > > > >
    > > > > > "Manish Bafna" wrote:
    > > > > >
    > > > > > > Hi,
    > > > > > > can you please tell at which line you are getting this error?Most probably
    > > > > > > you would be using this line of findcontrol in update event of DataGrid.If
    > > > > > > you give details as to where r using this code of findcontrol or in which
    > > > > > > event u r using then only i would be able to help you out.
    > > > > > >
    > > > > > > Thanks and Regards,
    > > > > > > Manish Bafna.
    > > > > > > MCP and MCTS.
    > > > > > >
    > > > > > > "Mike Collins" wrote:
    > > > > > >
    > > > > > > > Thanks, but I get an error: Object reference not set to an instance of an
    > > > > > > > object. Any idea on why that is happening?
    > > > > > > >
    > > > > > > > "Manish Bafna" wrote:
    > > > > > > >
    > > > > > > > > Hi,
    > > > > > > > > It should be:
    > > > > > > > > DataGrid dgDropDownMenus= (DataGrid)sender;
    > > > > > > > > if(e.Item.ItemType.ToString() != "Header" && e.Item.ItemType.ToString() !=
    > > > > > > > > "Footer")
    > > > > > > > > {
    > > > > > > > > string option = ((TextBox )e.Item.FindControl("txtName")).Text;
    > > > > > > > > }
    > > > > > > > >
    > > > > > > > > Although i have written this code for Datagrid, you can use same for
    > > > > > > > > gridview with little or no modification.
    > > > > > > > > Thanks and Regards,
    > > > > > > > > Manish Bafna.
    > > > > > > > > MCP and MCTS.
    > > > > > > > >
    > > > > > > > > "Mike Collins" wrote:
    > > > > > > > >
    > > > > > > > > > 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>
    > > > > > > > > >
    > > > > > > > > >
     
    =?Utf-8?B?TWFuaXNoIEJhZm5h?=, Dec 23, 2006
    #10
  11. Ok...I'll check it again.

    "Manish Bafna" wrote:

    > Hi,
    > I think the error u r getting in quick watch is the bug in the microsoft
    > product.See below link:
    > http://www.kbalertz.com/Feedback_814828.aspx
    > I think you r now able to get text of textbox in datagrid.
    >
    >
    > "Mike Collins" wrote:
    >
    > > Still an error.
    > >
    > > error: identifier 'option' out of scope, when I checked the object "option"
    > > after running the code. It was not a run time error, I did a quick watch and
    > > saw it.
    > >
    > > "Manish Bafna" wrote:
    > >
    > > > Hi,
    > > > so finally it was solved or you r still getting some errors?
    > > >
    > > > "Mike Collins" wrote:
    > > >
    > > > > I had to change your code where you had the "as TextBox" because it caused an
    > > > > error to the following:
    > > > >
    > > > > this.dgDropDownMenus.EditItemIndex = e.Item.ItemIndex;
    > > > > TextBox option =
    > > > > (TextBox)dgDropDownMenus.Items[this.dgDropDownMenus.EditItemIndex].FindControl("txtName");
    > > > >
    > > > > Then I got the following error: error: identifier 'option' out of scope,
    > > > > when I checked the object "option" after running the code. It was not a run
    > > > > time error, I did a quick watch.
    > > > >
    > > > > I appreciate your patience and help in trying to help me figure this out.
    > > > >
    > > > > "Manish Bafna" wrote:
    > > > >
    > > > > > Hi,
    > > > > > Try this one:
    > > > > > this.dgMenus.EditItemIndex = e.Item.ItemIndex;
    > > > > > dgMenus.Items[this.DataGrid1.EditItemIndex].FindControl("txtName") as TextBox
    > > > > >
    > > > > > Thanks and Regards,
    > > > > > Manish Bafna.
    > > > > > MCP and MCTS.
    > > > > >
    > > > > >
    > > > > > "Mike Collins" wrote:
    > > > > >
    > > > > > > Sorry for the incomplete response. Below is the event that is running, and I
    > > > > > > am getting an error on the first line of the method "string option..."
    > > > > > >
    > > > > > > private void dgDropDownMenus_EditCommand(object source,
    > > > > > > System.Web.UI.WebControls.DataGridCommandEventArgs e)
    > > > > > > {
    > > > > > > string option = ((TextBox)e.Item.FindControl("txtName")).Text;
    > > > > > > Server.Transfer("../surveys/manageansweroptions.aspx?AnswerGroupID=" +
    > > > > > > dgDropDownMenus.DataKeys[e.Item.ItemIndex].ToString() + "&CallingPage=Manage
    > > > > > > Dropdowns Page&ReturnURL=ManageDropDowns.aspx&option=" +
    > > > > > > rblOption.SelectedItem.Value + "&GroupName=" +
    > > > > > > dgDropDownMenus.Items[e.Item.ItemIndex].Cells[2].Text);
    > > > > > > }
    > > > > > >
    > > > > > >
    > > > > > > "Manish Bafna" wrote:
    > > > > > >
    > > > > > > > Hi,
    > > > > > > > can you please tell at which line you are getting this error?Most probably
    > > > > > > > you would be using this line of findcontrol in update event of DataGrid.If
    > > > > > > > you give details as to where r using this code of findcontrol or in which
    > > > > > > > event u r using then only i would be able to help you out.
    > > > > > > >
    > > > > > > > Thanks and Regards,
    > > > > > > > Manish Bafna.
    > > > > > > > MCP and MCTS.
    > > > > > > >
    > > > > > > > "Mike Collins" wrote:
    > > > > > > >
    > > > > > > > > Thanks, but I get an error: Object reference not set to an instance of an
    > > > > > > > > object. Any idea on why that is happening?
    > > > > > > > >
    > > > > > > > > "Manish Bafna" wrote:
    > > > > > > > >
    > > > > > > > > > Hi,
    > > > > > > > > > It should be:
    > > > > > > > > > DataGrid dgDropDownMenus= (DataGrid)sender;
    > > > > > > > > > if(e.Item.ItemType.ToString() != "Header" && e.Item.ItemType.ToString() !=
    > > > > > > > > > "Footer")
    > > > > > > > > > {
    > > > > > > > > > string option = ((TextBox )e.Item.FindControl("txtName")).Text;
    > > > > > > > > > }
    > > > > > > > > >
    > > > > > > > > > Although i have written this code for Datagrid, you can use same for
    > > > > > > > > > gridview with little or no modification.
    > > > > > > > > > Thanks and Regards,
    > > > > > > > > > Manish Bafna.
    > > > > > > > > > MCP and MCTS.
    > > > > > > > > >
    > > > > > > > > > "Mike Collins" wrote:
    > > > > > > > > >
    > > > > > > > > > > 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>
    > > > > > > > > > >
    > > > > > > > > > >
     
    =?Utf-8?B?TWlrZSBDb2xsaW5z?=, Dec 23, 2006
    #11
  12. Thank you for your help. Found out that I had a type in the html of the
    datagrid that was causing the problem.

    "Manish Bafna" wrote:

    > Hi,
    > I think the error u r getting in quick watch is the bug in the microsoft
    > product.See below link:
    > http://www.kbalertz.com/Feedback_814828.aspx
    > I think you r now able to get text of textbox in datagrid.
    >
    >
    > "Mike Collins" wrote:
    >
    > > Still an error.
    > >
    > > error: identifier 'option' out of scope, when I checked the object "option"
    > > after running the code. It was not a run time error, I did a quick watch and
    > > saw it.
    > >
    > > "Manish Bafna" wrote:
    > >
    > > > Hi,
    > > > so finally it was solved or you r still getting some errors?
    > > >
    > > > "Mike Collins" wrote:
    > > >
    > > > > I had to change your code where you had the "as TextBox" because it caused an
    > > > > error to the following:
    > > > >
    > > > > this.dgDropDownMenus.EditItemIndex = e.Item.ItemIndex;
    > > > > TextBox option =
    > > > > (TextBox)dgDropDownMenus.Items[this.dgDropDownMenus.EditItemIndex].FindControl("txtName");
    > > > >
    > > > > Then I got the following error: error: identifier 'option' out of scope,
    > > > > when I checked the object "option" after running the code. It was not a run
    > > > > time error, I did a quick watch.
    > > > >
    > > > > I appreciate your patience and help in trying to help me figure this out.
    > > > >
    > > > > "Manish Bafna" wrote:
    > > > >
    > > > > > Hi,
    > > > > > Try this one:
    > > > > > this.dgMenus.EditItemIndex = e.Item.ItemIndex;
    > > > > > dgMenus.Items[this.DataGrid1.EditItemIndex].FindControl("txtName") as TextBox
    > > > > >
    > > > > > Thanks and Regards,
    > > > > > Manish Bafna.
    > > > > > MCP and MCTS.
    > > > > >
    > > > > >
    > > > > > "Mike Collins" wrote:
    > > > > >
    > > > > > > Sorry for the incomplete response. Below is the event that is running, and I
    > > > > > > am getting an error on the first line of the method "string option..."
    > > > > > >
    > > > > > > private void dgDropDownMenus_EditCommand(object source,
    > > > > > > System.Web.UI.WebControls.DataGridCommandEventArgs e)
    > > > > > > {
    > > > > > > string option = ((TextBox)e.Item.FindControl("txtName")).Text;
    > > > > > > Server.Transfer("../surveys/manageansweroptions.aspx?AnswerGroupID=" +
    > > > > > > dgDropDownMenus.DataKeys[e.Item.ItemIndex].ToString() + "&CallingPage=Manage
    > > > > > > Dropdowns Page&ReturnURL=ManageDropDowns.aspx&option=" +
    > > > > > > rblOption.SelectedItem.Value + "&GroupName=" +
    > > > > > > dgDropDownMenus.Items[e.Item.ItemIndex].Cells[2].Text);
    > > > > > > }
    > > > > > >
    > > > > > >
    > > > > > > "Manish Bafna" wrote:
    > > > > > >
    > > > > > > > Hi,
    > > > > > > > can you please tell at which line you are getting this error?Most probably
    > > > > > > > you would be using this line of findcontrol in update event of DataGrid.If
    > > > > > > > you give details as to where r using this code of findcontrol or in which
    > > > > > > > event u r using then only i would be able to help you out.
    > > > > > > >
    > > > > > > > Thanks and Regards,
    > > > > > > > Manish Bafna.
    > > > > > > > MCP and MCTS.
    > > > > > > >
    > > > > > > > "Mike Collins" wrote:
    > > > > > > >
    > > > > > > > > Thanks, but I get an error: Object reference not set to an instance of an
    > > > > > > > > object. Any idea on why that is happening?
    > > > > > > > >
    > > > > > > > > "Manish Bafna" wrote:
    > > > > > > > >
    > > > > > > > > > Hi,
    > > > > > > > > > It should be:
    > > > > > > > > > DataGrid dgDropDownMenus= (DataGrid)sender;
    > > > > > > > > > if(e.Item.ItemType.ToString() != "Header" && e.Item.ItemType.ToString() !=
    > > > > > > > > > "Footer")
    > > > > > > > > > {
    > > > > > > > > > string option = ((TextBox )e.Item.FindControl("txtName")).Text;
    > > > > > > > > > }
    > > > > > > > > >
    > > > > > > > > > Although i have written this code for Datagrid, you can use same for
    > > > > > > > > > gridview with little or no modification.
    > > > > > > > > > Thanks and Regards,
    > > > > > > > > > Manish Bafna.
    > > > > > > > > > MCP and MCTS.
    > > > > > > > > >
    > > > > > > > > > "Mike Collins" wrote:
    > > > > > > > > >
    > > > > > > > > > > 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>
    > > > > > > > > > >
    > > > > > > > > > >
     
    =?Utf-8?B?TWlrZSBDb2xsaW5z?=, Dec 23, 2006
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sid
    Replies:
    4
    Views:
    589
  2. ad

    When need to use FindControl

    ad, Apr 28, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    446
    Karl Seguin
    Apr 28, 2005
  3. sck10
    Replies:
    6
    Views:
    19,857
    UdayGaikwad
    Oct 24, 2011
  4. Paul
    Replies:
    1
    Views:
    38,910
    Nathan Sokalski
    Feb 25, 2006
  5. John Kotuby
    Replies:
    5
    Views:
    396
    John Kotuby
    Dec 12, 2007
Loading...

Share This Page