GridView la Façon d'obtenir la valeur d'une zone de texte à MODIFIER MDOE

J'ai un gridview qui est lié aux données des articles. il est lié à un SQLDATASOURCE. La valeur par défaut Modifier, mettre à Jour fonctionne très bien, cependant, j'ai voulu effectuer une requête trop lorsque l'utilisateur met à jour la ligne.

Voici mon 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>

Et voici mon Code c#

  protected void RunCustomMethod(object sender, GridViewCommandEventArgs e)
{
//Custom Method To Update Row
if (e.CommandName == "myCustomUpdateMethod")
{
int customerID = Convert.ToInt32(e.CommandArgument);
SqlConnection conn = new SqlConnection(SqlDataSource1.ConnectionString);
SqlCommand Cmd = new SqlCommand();
try
{
conn.Open();
Cmd.CommandText = "update Customers set customer_name = '" + **I WANT TO GET THE UPDATED VALUE BUT FROM WHERE SHALL I GET IT?????** + "', modified_on = getdate(), modified_by = '" + System.Environment.UserName + "' where customer_id = '" + customerID + "'";
Cmd.CommandType = System.Data.CommandType.Text;
Cmd.Connection = conn;
Cmd.ExecuteNonQuery();
GridView1.DataBind();
//Close the Edit Mode
GridView1.EditIndex = -1;
}
catch (SqlException ee)
{
ValidationError.Display(ee.Message);
}
finally
{
Cmd.Dispose();
conn.Close();
conn.Dispose();
}
}
}
}

Toute aide serait grandement appréciée

InformationsquelleAutor Shezi | 2012-09-14