我正在制作 QueryString 参数,所以我有两个 .aspx 表单。一个表单Default.aspx
包含三个字段 SId、FirstName、LastName。当我提交值时,这些值将保存在数据库中。现在我想在网格上显示特定 SId 上的这些数据default2.aspx
。网格通过 SqlDataSource 获取数据。所以我想在单击按钮时调用 SqlDataSource,网格应该显示特定 SId 上的数据default2.aspx
。
默认.aspx:
<body>
<form id="form1" runat="server">
<div>
</div>
<table cellpadding="2" cellspacing="5">
<tr>
<td>
<asp:Label ID="lblId" runat="server" Text="SId"></asp:Label>
</td>
<td>
<asp:TextBox ID="tbid" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblname" runat="server" Text="FirstName"></asp:Label>
</td>
<td>
<asp:TextBox ID="tbfirstname" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lbllastname" runat="server" Text="LastName"></asp:Label>
</td>
<td>
<asp:TextBox ID="tblastname" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnsubmit" runat="server" Text="Submit"
onclick="btnsubmit_Click1" Width="102px" />
</td>
</tr>
</table>
<br />
</form>
</body>
默认2.aspx:
<body>
<form id="form1" runat="server">
<div>
<table cellpadding="2" cellspacing="5">
<tr>
<td>
SId</td>
<td>
<asp:TextBox ID="tbId" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnSearch" runat="server" Text="Search"
onclick="btnSearch_Click" />
</td>
</tr>
</table>
</div>
<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
AutoGenerateSelectButton="True"
DataSourceID="SqlDataSource1" EnableModelValidation="True"
onrowcommand="GridView1_RowCommand">
<Columns>
<asp:TemplateField HeaderText="SId">
<ItemTemplate>
<asp:Label ID="lblSId" runat="server" Text='<%# Bind("SId") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="FirstName">
<ItemTemplate>
<asp:Label ID="lblFirstName" runat="server" Text='<%# Bind("FirstName")%>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="LastName">
<ItemTemplate>
<asp:Label ID="lblLastName" runat="server" Text='<%# Bind("LastName")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:testConnectionString %>"
SelectCommand="SELECT * FROM [Student] where SId = @tbId">
<SelectParameters>
<asp:QueryStringParameter Name="SId" QueryStringField="SId" />
</SelectParameters>
</asp:SqlDataSource>
</form>
</body>
我想在按钮单击时调用 SqlDataSource1 像..
Default2.aspx.cs:
protected void btnSearch_Click(object sender, EventArgs e)
{
string SId = tbId.Text;
SqlDataSource1.DataBind();
}