This example shows how to modify the data selected using the value passed from select HtmlControl. SqlDataAdapter maintains a set of Parameters that can be used to replace variable Identifiers (represented by "@" before the name) with values. Add a new SqlParameter with the name, type, and size of the specified parameter to the set, and set its Value attribute to the selected Value.
Add the following code to the html code of aspx:
<Body MS_POSITIONING = "GridLayout">
<Form runat = "server" ID = "Form1">
<H3> <font face = ""> parameterized selection of the DataGrid Control </font>
Select state:
<Select id = "MySelect" runat = "server" NAME = "MySelect">
<Option selected> CA </option>
<Option> IN </option>
<Option> KS </option>
<Option> MD </option>
<Option> MI </option>
<Option> OR </option>
<Option> TN </option>
<Option> UT </option>
</Select>
<Input type = "submit" Value = "Get Author" runat = "server" ID = "Submit1" NAME = "Submit1"> <p>
<ASP: dataGrid id = "MyDataGrid" runat = "server" Width = "700" BackColor = "# ccccff" BorderColor = "black" ShowFooter = "false" CellPadding = "3" CellSpacing =" 0 "Font-Name =" "Font-Size =" 8pt "HeaderStyle-BackColor =" # aaaadd "EnableViewState =" false "/>
</Form>
</Body>
Add the following code to the aspx. cs file:
Private void Submit1_ServerClick (object sender, System. EventArgs e)
{
String strconn = "user id = sa; password =; initial catalog = pubs; data source = jeff ";
SqlConnection myConnection = new SqlConnection (strconn );
String selectCmd = "select * from Authors where state = @ State ";