【发布时间】:2014-01-09 20:29:25
【问题描述】:
我需要检查复选框是否被选中,然后将用户选择的数据行保存到我的数据库中,但我什至不知道如何开始。
这包括如何将数据保存到我的数据库中。
仅供参考:复选框位于“GridView”内部,然后位于“ItemTemplate”内部。
如果您不确定我想要达到的目标,请询问,我会尽量让您更清楚。 这是我到目前为止的代码:
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="TestCreation.aspx.vb" Inherits="SpellingBee.testcreation1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h1>Compile Your Tests</h1>
<asp:GridView ID="CreateTest" runat="server"
AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="QuestionID" DataSourceID="SqlDataSource1" ForeColor="#333333"
GridLines="None">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="QuestionSelector" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="QuestionID" HeaderText="QuestionID"
InsertVisible="False" ReadOnly="True" SortExpression="QuestionID" />
<asp:BoundField DataField="Answer" HeaderText="Answer"
SortExpression="Answer" />
<asp:BoundField DataField="Question" HeaderText="Question"
SortExpression="Question" />
<asp:BoundField DataField="SubjectID" HeaderText="SubjectID"
SortExpression="SubjectID" />
<asp:TemplateField></asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="SELECT [QuestionID], [Answer], [Question], [SubjectID] FROM [Question]">
</asp:SqlDataSource>
<asp:Button ID="QuestionCompiler" runat="server" Text="Compile Selected Questions" />
<h1>Preview Previous Tests</h1>
</asp:Content>
下面是代码:
Public Class testcreation1
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Session.Item("User Type") <> "Teacher" Then
Response.Redirect("/")
End If
End Sub
Protected Sub QuestionCompiler_Click(sender As Object, e As EventArgs) Handles QuestionCompiler.Click
End Sub
End Class
<h1>Preview Previous Tests</h1>
</asp:Content>
提前致谢!
【问题讨论】:
标签: asp.net database vb.net gridview checkbox