locked
how to find Text box value from grid RRS feed

  • Question

  • User102501961 posted

    grid view 

    <asp:GridView ID="ViewOfo" runat="server" CellPadding="4" CssClass="Grid" EmptyDataText="No Data Available" EmptyDataRowStyle-BorderStyle="Solid" EmptyDataRowStyle-BorderWidth="2px" EmptyDataRowStyle-BorderColor="Red" Caption='<table border="1" width="100%" cellpadding="0" cellspacing="0" ><tr><td><center><font color="black"><b>Cell Today</b></font></center></td></tr></table>' OnRowCommand="gvTodayData_RowCommand" Width="100%" ForeColor="Black" DataKeyNames="Empid" PageSize="25" AutoGenerateColumns="False" AllowPaging="True" GridLines="Horizontal" Style="margin-right: 0px;" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" Font-Names="Verdana" Font-Size="Small" OnPageIndexChanging="gridview1_PageIndexChanging">
    <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
    <HeaderStyle BackColor="#333333" Font-Bold="True" HorizontalAlign="Left" ForeColor="White" Font-Names="Verdana" Font-Size="Small" />
    <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
    <RowStyle HorizontalAlign="Left" Height="30" />

    <AlternatingRowStyle BackColor="White" />

    <Columns>

    <asp:TemplateField HeaderText="Employee Id" Visible="false" >
    <ItemTemplate>
    <asp:Label ID="id" runat="server" Text='<%#Eval("EMPID") %>' CssClass="clsWrap" Width="100px"></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>


    <asp:TemplateField HeaderText="Out Of Office On">
    <ItemTemplate>
    <asp:Label ID="Date" runat="server" Text='<%#Eval("OFO_DATE","{0:dd/MM/yyy}") %>' CssClass="clsWrap" Width="100px"></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="APPLIED DATE" >
    <ItemTemplate >
    <asp:Label ID="Name" runat="server" Text='<%#Eval("APPLIED_DATE","{0:dd/MM/yyy}") %>' CssClass="clsWrap" Width="100px"></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>

    <asp:TemplateField HeaderText="Task" ItemStyle-Wrap="True">
    <ItemTemplate>
    <asp:Label ID="Task" runat="server" Text='<%#Eval("TASK") %>' CssClass="clsWrap" Width="250px"></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>

    <asp:TemplateField HeaderText="Employee Review">
    <ItemTemplate>
    <asp:Label ID="Starttime" runat="server" Text='<%#Eval("EMP_REMARKS") %>' CssClass="clsWrap" Width="100px"></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Manager Remark">
    <ItemTemplate>
    <asp:TextBox ID="txtRemark" MaxLength="100" style=" width: 117px;" runat="server"></asp:TextBox>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Done">
    <ItemTemplate>
    <asp:LinkButton ID="btnApproved" runat="server" CommandName="Done" CommandArgument='<%#Eval("EMPID")+"~"+Eval("OFO_DATE")+"~"+Eval("APPLIED_DATE")+"~"+Eval("TASK")+"~"+Eval("EMP_REMARKS")%>'><img src="../Images/right_mark.jpg" /></asp:LinkButton>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Rejected">
    <ItemTemplate>
    <asp:LinkButton ID="btnRejcted" runat="server" CommandName="Rejcted" CommandArgument='<%#Eval("EMPID")+"~"+Eval("OFO_DATE")+"~"+Eval("APPLIED_DATE")+"~"+Eval("TASK")+"~"+Eval("EMP_REMARKS")%>'>Rejected</asp:LinkButton>
    </ItemTemplate>
    </asp:TemplateField>

    </Columns>
    <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
    <SortedAscendingCellStyle BackColor="#F7F7F7" />
    <SortedAscendingHeaderStyle BackColor="#4B4B4B" />
    <SortedDescendingCellStyle BackColor="#E5E5E5" />
    <SortedDescendingHeaderStyle BackColor="#242121" />
    </asp:GridView>

    i want to find that text box value into that var a

    in Cs File

    GridViewRow select=(GridViewRow)((LinkButton)e.CommandSource).NamingContainer;

    TextBox txt=(TextBox)select.Cells[5].FindControl ("txtRemark");
    var a=txt.Text;

    Monday, June 1, 2015 1:14 AM

Answers

  • User-1716253493 posted

    The textbox is in Column[4] instead column[5]

    You can do like this

    GridViewRow select=(GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
    TextBox txt=(TextBox)select.FindControl ("txtRemark");

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 1, 2015 2:48 AM

All replies

  • User724169276 posted
    GridViewRow clickedRow = ((LinkButton) sender).NamingContainer as GridViewRow;
    TextBox txt=(TextBox)clickedRow.FindControl("txtRemark");
    var a=txt.Text;

    Monday, June 1, 2015 1:56 AM
  • User102501961 posted

    InvalidCastException: Unable to cast object of type 'System.Web.UI.WebControls.GridView' to type 'System.Web.UI.WebControls.LinkButton'.

    protected void gvTodayData_RowCommand(object sender, GridViewCommandEventArgs e)
    Line 35:         {
    Line 36:             GridViewRow clickedRow=((LinkButton)sender).NamingContainer as GridViewRow;
    Line 37:             TextBox txt=(TextBox)clickedRow.FindControl ("txtRemark");
    Line 38:             var a=txt.Text;
    Monday, June 1, 2015 2:13 AM
  • User-1716253493 posted

    The textbox is in Column[4] instead column[5]

    You can do like this

    GridViewRow select=(GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
    TextBox txt=(TextBox)select.FindControl ("txtRemark");

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 1, 2015 2:48 AM
  • User102501961 posted
    protected void gvTodayData_RowCommand(object sender, GridViewCommandEventArgs e)
            {
                //finding row text box (ravi sir)
                GridViewRow select=(GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
                TextBox txt=(TextBox)select.Cells[4].FindControl ("txtRemark");
    var a=txt.Text;
    }

    i tried both  But not getting the value :/

    Monday, June 1, 2015 3:21 AM
  • User-1716253493 posted

    Try change to

    TextBox txt=(TextBox)select.FindControl("txtRemark");

    And make sure you are not binding the grid in every postback

    Monday, June 1, 2015 3:24 AM
  • User102501961 posted

    i change that one also value getting  empty  :/ 

    Monday, June 1, 2015 3:34 AM
  • User102501961 posted

    Try change to

    TextBox txt=(TextBox)select.FindControl("txtRemark");

    And make sure you are not binding the grid in every postback

    its working now :D thank you sir 

    Monday, June 1, 2015 7:06 AM