扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
<asp:Gridview ID="Gridview1" Runat="server" DataSourceID="SqlDataSource1" DataKeyNames="CustomerID" AutoGenerateColumns="False" ShowFooter="True"> <Columns> <asp:TemplateField> <ItemTemplate> <asp:Label ID="CustomerIDLabel" Runat="Server"><%# Eval("CustomerID") %></asp:Label> </ItemTemplate> <FooterTemplate> <asp:TextBox ID="CustomerIDTextBox" Runat="server"></asp:TextBox> </FooterTemplate> </asp:TemplateField> <asp:TemplateField> <ItemTemplate> <asp:Label ID="CompanyNameLabel" Runat="Server"><%# Eval("CompanyName") %></asp:Label> </ItemTemplate> <FooterTemplate> <asp:TextBox ID="CompanyNameTextBox" Runat="server"></asp:TextBox> </FooterTemplate> </asp:TemplateField> <asp:TemplateField> <FooterTemplate> <asp:DropDownList ID="ContactTitleDropDownList" Runat="server" DataSourceID="SqlDataSource2" DataTextField="ContactTitle" DataValueField="ContactTitle"> </asp:DropDownList> <asp:SqlDataSource ID="SqlDataSource2" Runat="server" SelectCommand="SELECT DISTINCT [ContactTitle] FROM [Customers]" ConnectionString="server=localhost;uid=sa;password=xxx;database=northwind"> </asp:SqlDataSource> <asp:Button ID="Button1" Runat="server" Text="Add" OnClick="Button1_Click" /> <asp:Button ID="CancelButton1" Runat="server" Text="Cancel" OnClick="CancelButton1_Click" /> </FooterTemplate> <ItemTemplate> <asp:DropDownList ID="ContactTitleDropDown" SelectedValue=’<%# Bind("ContactTitle") %>’ Runat="Server" DataSourceID="SqlDataSource3" DataTextField="ContactTitle" DataValueField="ContactTitle" ></asp:DropDownList> <asp:SqlDataSource ID="SqlDataSource3" Runat="server" SelectCommand="SELECT DISTINCT [ContactTitle] FROM [Customers]" ConnectionString="server=localhost;uid=sa;password=xxxx;database=northwind" EnableCaching="True"> </asp:SqlDataSource> </ItemTemplate> </asp:TemplateField> </Columns> </asp:Gridview> |
<script runat="server"> void CancelButton1_Click(object sender, EventArgs e) { Gridview1.ShowFooter = false; } void AddButton1_Click(object sender, EventArgs e) { Gridview1.ShowFooter = true; } //点add按钮时,将新增的记录更新到数据库中去 void Button1_Click(object sender, EventArgs e) { TextBox customerID = Gridview1.FooterRow.FindControl("CustomerIDTextBox") as TextBox; TextBox companyName = Gridview1.FooterRow.FindControl("CompanyNameTextBox") as TextBox; DropDownList ContactTitle = Gridview1.FooterRow.FindControl("ContactTitleDropDownList") as DropDownList; SqlDataSource1.InsertParameters["CustomerID"].DefaultValue = customerID.Text; SqlDataSource1.InsertParameters["CompanyName"].DefaultValue = companyName.Text; SqlDataSource1.InsertParameters["ContactTitle"].DefaultValue=ContactTitle.SelectedValue; SqlDataSource1.Insert(); } </script> |
<asp:SqlDataSource ID="SqlDataSource1" Runat="server" InsertCommand="INSERT INTO [Customers] ([CustomerID], [CompanyName], [ContactTitle]) VALUES (@CustomerID, @CompanyName, @ContactTitle)" SelectCommand="SELECT top 5 [CustomerID], [CompanyName], [ContactTitle] FROM [Customers]" ConnectionString="server=localhost;uid=sa;password=XXXXX;database=northwind"> <InsertParameters> <asp:Parameter Type="String" Name="CustomerID"></asp:Parameter> <asp:Parameter Type="String" Name="CompanyName"></asp:Parameter> <asp:Parameter Type="String" Name="ContactTitle"></asp:Parameter> </InsertParameters> </asp:SqlDataSource> |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者