2

Currently i'm working on my final year project. In a webpage which loads data in gridview, each row has on button which will popup a window and ask for error to write inside **textbox** and submit that error on server. On the serverside i require two values, first one is the primary key of that row and the error that is written inside **textbox**. It is easy to get primary key value but i'm unable to get value in side the textbox. I'm attaching the code of .aspx file:

<asp:GridView ID="gvPODetails" runat="server" DataSourceID="Inspection_SqlDataSource"
            EnableModelValidation="True" AllowSorting="True" AutoGenerateColumns="False"
            BackColor="#CCCCCC" BorderColor="Black" BorderStyle="Solid" BorderWidth="3px" CellPadding="4" ForeColor="Black" CellSpacing="2">
            <Columns>
                <asp:BoundField DataField="ProductCode" HeaderText="ProductCode" SortExpression="ProductCode" />
                <asp:BoundField DataField="MaterialCode" HeaderText="MaterialCode" SortExpression="MaterialCode" />
                <asp:TemplateField>
                    <ItemStyle BorderStyle="None" BorderColor="Transparent" BorderWidth="0px" />
                    <ItemTemplate>
                        <asp:LinkButton ID="lnkbtnOk" OnClick="Ok_Click" CommandArgument='<%# Eval("Identity")%>'
                            runat="server" Text="Ok"></asp:LinkButton>
                        <asp:LinkButton ID="lnkbtnReject" runat="server" Text="Reject"></asp:LinkButton>                        
                        <asp:Panel ID="popUp_Data" runat="server" CssClass="modelPopup" Style="display: none;">
                            <table style="padding: 10px 10px 10px 10px; width: 100%;">
                                <tr>
                                    <td>
                                    </td>
                                    <td align="right">
                                        <input id="close_popup" type="image" src="../Images/closebox.gif" />
                                    </td>
                                </tr>
                                <tr valign="top">
                                    <td align="right">
                                        <asp:Label ID="lblError" Text="Error" runat="server" CssClass="fontStyle"></asp:Label>
                                    </td>
                                    <td align="left">
                                        <asp:TextBox ID="txtError" runat="server" CssClass="ta"
                                            TextMode="MultiLine"></asp:TextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                    </td>
                                    <td align="left">
                                        <asp:Button ID="btnSubmit" runat="server" CssClass="sbmt" Text="Reject Item" OnClick="Reject_Click"
                                            CommandArgument='<%# Eval("Identity")%>' />
                                    </td>
                                </tr>
                            </table>
                        </asp:Panel>                               
                        <asp:ModalPopupExtender ID="popUp_Data_ModalPopupExtender" runat="server" DynamicServicePath=""
                            Enabled="True" BackgroundCssClass="modelBackground" PopupControlID="popUp_Data"
                            TargetControlID="lnkbtnReject" CancelControlID="close_popup">
                        </asp:ModalPopupExtender>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <EmptyDataTemplate>
                <asp:Label runat="server" ID="lblNoDataFound" Text="No Machine Found."></asp:Label>
            </EmptyDataTemplate>
        </asp:GridView>

What i want is the data inside textbox with id txtError.

Dipen Shah
  • 25,562
  • 1
  • 32
  • 58

1 Answers1

2

Since it is a repeating item, you cannot access it directly using its id. You can use FindControl instead as follows:

var textBoxAux = gridView.Rows[index].FindControl("txtError") as TextBox;

You need to find the index of the row in the event you are handling.

EDIT: finding the index...

Pass the DataItemIndex in the CommandArgument ( instead of the identity ) if applicable.

CommandArgument='<%# Container.DataItemIndex %>'

Ref: ASP.NET GridView RowIndex As CommandArgument

Community
  • 1
  • 1
Orkun
  • 6,998
  • 8
  • 56
  • 103
  • Thanks...First i had compared all values for match in primary but than i show your reply and changed my method to efficient one. – Dipen Shah Jan 30 '12 at 15:49