在运行时使用gridview将数据插入数据库 [英] Inserting data into database using gridview at runtime
本文介绍了在运行时使用gridview将数据插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含两列的网格视图。一个名为 Reg_No ,另一个名为 Marks (在模板字段中用ItemTemplate中的TextBox标记列)。
Reg_No列绑定到College表,它显示来自数据库thro sql数据源的reg_nos。
我需要将值插入到同一个数据库表中学院通过网格视图中的文本框,但我不知道如何做到这一点。这是我的代码:
I have a grid view with two columns. One named Reg_No and the other named Marks (Marks columns in template field with TextBox in ItemTemplate).
The Reg_No column is bound to the "College" table and it displays the reg_nos from database thro sql datasource.
I need to insert the values into the same database table "College" through textbox in grid view, but I am not sure how to do this. Here is my code:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" DataSourceMode="DataSet"
ConnectionString="<%$ ConnectionStrings:WCCConnectionString %>"
SelectCommand="SELECT [Reg_No] FROM [College] " >
</asp:SqlDataSource>
<br />
<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333"
GridLines="None" Height="283px" Width="343px" >
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="Reg_No" HeaderText="Reg_No"
SortExpression="Reg_No" />
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<SortedAscendingCellStyle BackColor="#FDF5AC" />
<SortedAscendingHeaderStyle BackColor="#4D0000" />
<SortedDescendingCellStyle BackColor="#FCF6C0" />
<SortedDescendingHeaderStyle BackColor="#820000" />
<Columns>
<asp:TemplateField HeaderText="Marks">
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
推荐答案
ConnectionStrings:WCCConnectionString%>
SelectCommand =SELECT [Reg_No] FROM [College]>
< / asp:SqlDataSource>
< br />
< br />
< asp:GridView ID =GridView1runat =serverAutoGenerateColumns =False
CellPadding =4DataSourceID =SqlDataSource1ForeColor =#333333
GridLines =None高度=283pxWidth =343px>
< AlternatingRowStyle BackColor =White/>
< Columns>
< asp:BoundField DataField =Reg_NoHeaderText = Reg_No
SortExpression =Reg_No/>
< / Columns>
< FooterStyle BackColor =#990000Font-Bold =TrueForeColor =White/ >
< HeaderStyle BackColor =#990000Font-Bold =TrueForeColor =White/>
< PagerStyle BackColor =#FFCC66ForeColor =#333333HorizontalAlign =美分呃/>
< RowStyle BackColor =#FFFBD6ForeColor =#333333/>
< SelectedRowStyle BackColor =#FFCC66Font-Bold =TrueForeColor =Navy/>
< SortedAscendingCellStyle BackColor =#FDF5AC/>
< SortedAscendingHeaderStyle BackColor =#4D0000/>
< SortedDescendingCellStyle BackColor =#FCF6C0/>
< SortedDescendingHeaderStyle BackColor =#820000/>
< Columns>
< asp:TemplateField HeaderText =Marks>
< ItemTemplate>
< asp:TextBox ID =TextBox1runat =server>< / asp:TextBox>
< / ItemTemplate>
< / asp:TemplateField>
< / Columns>
< / asp:GridView>
ConnectionStrings:WCCConnectionString %>" SelectCommand="SELECT [Reg_No] FROM [College] " > </asp:SqlDataSource> <br /> <br /> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" Height="283px" Width="343px" > <AlternatingRowStyle BackColor="White" /> <Columns> <asp:BoundField DataField="Reg_No" HeaderText="Reg_No" SortExpression="Reg_No" /> </Columns> <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" /> <RowStyle BackColor="#FFFBD6" ForeColor="#333333" /> <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" /> <SortedAscendingCellStyle BackColor="#FDF5AC" /> <SortedAscendingHeaderStyle BackColor="#4D0000" /> <SortedDescendingCellStyle BackColor="#FCF6C0" /> <SortedDescendingHeaderStyle BackColor="#820000" /> <Columns> <asp:TemplateField HeaderText="Marks"> <ItemTemplate> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
查看示例 [ ^ ] :)
-KR
See this example[^] :)
-KR
这篇关于在运行时使用gridview将数据插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文