asp网站站点" rel="nofollow" />
在asp网站站点" rel="nofollow" />
<%@PageLanguage="C#"%>
<scriptrunat="server">
voidButton1_Click(objectsender,EventArgse)
{
for(inti=0;i<GridView1.Rows.Count;i++)
{
GridViewRowrow=GridView1.Rows[i];
SqlDataSource1.UpdateParameters[0].DefaultValue=((TextBox)row.Cells[0].FindControl("TextBox2")).Text;
SqlDataSource1.UpdateParameters[1].DefaultValue=((TextBox)row.Cells[1].FindControl("TextBox3")).Text;
SqlDataSource1.UpdateParameters[2].DefaultValue=GridView1.DataKeys[i].Value.ToString();
SqlDataSource1.Update();
}
}
</script>
<htmlxmlns="
<headrunat="server">
<title>UntitledPage</title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:GridViewID="GridView1"Runat="server"DataSourceID="SqlDataSource1"DataKeyNames="CustomerID" AutoGenerateColumns="False">
<Columns>
<asp:TemplateFieldSortExpression="CustomerID"HeaderText="CustomerID">
<ItemTemplate>
<asp:TextBoxRunat="server"Text='<%#Bind("CustomerID")%>'ID="TextBox1"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateFieldSortExpression="CompanyName"HeaderText="CompanyName">
<ItemTemplate>
<asp:TextBoxRunat="server"Text='<%#Bind("CompanyName")%>'ID="TextBox2"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateFieldSortExpression="ContactName"HeaderText="ContactTitle">
<ItemTemplate>
<asp:TextBoxRunat="server"Text='<%#Bind("ContactTitle")%>'ID="TextBox3"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSourceID="SqlDataSource1"Runat="server"
SelectCommand="SELECT[CustomerID],[CompanyName],[ContactName],[ContactTitle]FROM[Customers]"
UpdateCommand="UPDATE[Customers]SET[CompanyName]=@CompanyName,[ContactTitle]=@ContactTitleWHERE[CustomerID]=@CustomerID"
ConnectionString="<%$ConnectionStrings:AppConnectionString1%>">
<UpdateParameters>
<asp:ParameterType="String"Name="CompanyName"></asp:Parameter>
<asp:ParameterType="String"Name="ContactTitle"></asp:Parameter>
<asp:ParameterType="String"Name="CustomerID"></asp:Parameter>
</UpdateParameters>
</asp:SqlDataSource>
<asp:ButtonID="Button1"Runat="server"Text="Button"OnClick="Button1_Click"/>
</div>
</form>
</body>
</html>