Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# GridView如何从EDIT MDOE中的文本框中获取值_C#_Asp.net_Gridview_Sqldatasource - Fatal编程技术网

C# GridView如何从EDIT MDOE中的文本框中获取值

C# GridView如何从EDIT MDOE中的文本框中获取值,c#,asp.net,gridview,sqldatasource,C#,Asp.net,Gridview,Sqldatasource,我有一个包含数据绑定项的gridview。它绑定到一个SQLDATASOURCE。默认的编辑、更新工作正常,但是,当用户更新行时,我也想执行查询。 这是我的aspx <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Customer_id" DataSourceID="SqlDataSource1" EmptyDataText="T

我有一个包含数据绑定项的gridview。它绑定到一个SQLDATASOURCE。默认的编辑、更新工作正常,但是,当用户更新行时,我也想执行查询。
这是我的aspx

  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Customer_id"
        DataSourceID="SqlDataSource1" 
        EmptyDataText="There are no data records to display." AllowPaging="True" 
        AllowSorting="True" CellPadding="4" ForeColor="#333333" GridLines="Horizontal" 
        PageSize="5" Width="873px"  OnRowCommand = "RunCustomMethod" >
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        <Columns>
            <asp:TemplateField>
                <EditItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True"
                        CommandName="myCustomUpdateMethod" Text="Update" CommandArgument = '<%# Eval("Customer_ID") %>'
                        onclientclick="return Confirm ('Are You Sure You Want To Make These Changes?')"></asp:LinkButton>
                    &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                        CommandName="Cancel" Text="Cancel"></asp:LinkButton>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                        CommandName="Edit" Text="Edit" ></asp:LinkButton>
                    &nbsp;
                    <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                        CommandName="Select" Text="Select"></asp:LinkButton>
                    &nbsp;
                 </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="Customer_id" HeaderText="Customer_id" ReadOnly="True"
                SortExpression="Customer_id" InsertVisible="False" />
            <asp:TemplateField HeaderText="Customer_Name" SortExpression="Customer_Name">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Customer_Name") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("Customer_Name") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>

        </Columns>

    </asp:GridView>

非常感谢您提供的任何帮助

我想您需要的代码是:

GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
string name = ((TextBox)row.FindControl("TextBox1")).Text

Cmd.CommandText = "update Customers set customer_name = '" + name + "', modified_on = getdate(), modified_by = '" + System.Environment.UserName + "' where customer_id = '" + customerID + "'";

我认为您正在寻找的代码是:

GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
string name = ((TextBox)row.FindControl("TextBox1")).Text

Cmd.CommandText = "update Customers set customer_name = '" + name + "', modified_on = getdate(), modified_by = '" + System.Environment.UserName + "' where customer_id = '" + customerID + "'";

试着这样做:

string newTitle = ((TextBox)GridView_Galerie.Rows[e.RowIndex].FindControl("tb_titre")).Text;

试着这样做:

string newTitle = ((TextBox)GridView_Galerie.Rows[e.RowIndex].FindControl("tb_titre")).Text;

你听到的是错误的事件。如果希望在数据库中更新值之前获取这些值,则应收听
行更新
事件

参考:


同样,如果要在数据库中的值更新后运行查询,也会出现一个事件。

您正在侦听错误的事件。如果希望在数据库中更新值之前获取这些值,则应收听
行更新
事件

参考:


同样,如果要在数据库中的值更新后运行查询,也会出现一个事件。

重复问题。请参阅重复问题。请参考这一点,正中目标。谢谢这解决了我的问题:)没有问题,任何时候;o) 很乐意帮忙!切中要害,恰到好处。谢谢这解决了我的问题:)没有问题,任何时候;o) 很乐意帮忙!您无法从EventArgs直接获取此事件的RowIndex-您的解决方案使用OnRowDataBound但不使用OnRowCommands您无法从EventArgs直接获取此事件的RowIndex-您的解决方案使用OnRowDataBound但不使用OnRowCommands