所以我创建这个.NET表单,以不同的形式获取值,并将tham添加到SQL本地数据库。到目前为止,我已经想出如何从单选按钮获取和插入值,从单选按钮,但现在我不知道如何从DropDownList插入数据库值。下面我展示了我的一些代码。希望你能帮助我。 :))
<td class="auto-style1">
<label for="TextBox5">Mosha:</label>
</td>
<td class="auto-style1">
<telerik:RadDropDownList ID="RadDropDownList1" runat="server" SelectedText=" ">
<Items>
<telerik:DropDownListItem runat="server" Selected="True" Text=" " />
<telerik:DropDownListItem runat="server" Text="30-35 vjec" />
<telerik:DropDownListItem runat="server" Text="35-40 vjec" />
<telerik:DropDownListItem runat="server" Text="40-45 vjec" />
<telerik:DropDownListItem runat="server" Text="40 < vjec" />
</Items>
</telerik:RadDropDownList>
</td></tr
<tr></tr><td class="auto-style1"><label for="TextBox3">Departamenti:</label>
</td><td class="auto-style1">
<telerik:RadDropDownList ID="SelectDepartament" DefaultMessage="Select a product" runat="server" SelectedText="Departamenti i Risqeve">
<Items>
<telerik:DropDownListItem runat="server" Selected="True" Text=" " />
<telerik:DropDownListItem runat="server" Text="Departamenti i Menaxhimit" />
<telerik:DropDownListItem runat="server" Text="Departamenti i IT" />
<telerik:DropDownListItem runat="server" Text="DropDownListItem4" />
<telerik:DropDownListItem runat="server" Text="DropDownListItem5" />
<telerik:DropDownListItem runat="server" Text="DropDownListItem6" />
</Items></telerik:RadDropDownList>
</td>
<tr>
<td class="auto-style1">
<label for="TextBox6">Te drejtat ne Internet:</label>
</td>
<td class="auto-style1">
<telerik:RadDropDownList ID="RadDropDownList2" DefaultMessage=" " runat="server">
<Items>
<telerik:DropDownListItem runat="server" Text="Kategoria A" />
<telerik:DropDownListItem runat="server" Text="Kategoria B" />
<telerik:DropDownListItem runat="server" Text="Kategoria C" />
</Items>
</telerik:RadDropDownList>
</td>
protected void Save2_Click(object sender, EventArgs e)
{
try{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Rights"].ConnectionString);
con.Open();
string insert = "insert into Rights(Name,Mbiemri,Gjinia,Departamenti,Mosha,IntRights,Transferat, Depozite,Raporte) values (@Name,@Mbiemri,@Gjinia,@Departamenti,@Mosha,@IntRights,@Transferta,@Depozite,@Raporte)";
SqlCommand cnd = new SqlCommand(insert, con);
cnd.Parameters.AddWithValue("@Name", TextBox1.Text);
cnd.Parameters.AddWithValue("@Mbiemri", TextBox2.Text);
cnd.Parameters.AddWithValue("@Gjinia", RadioButtonList1.Text);
cnd.Parameters.AddWithValue("@Departamenti", TextBox2.Text);
cnd.Parameters.AddWithValue("@Mosha", TextBox2.Text);
cnd.Parameters.AddWithValue("@IntRights", TextBox2.Text);
cnd.Parameters.AddWithValue("@Transferta", TransfertaBtn.Text);
cnd.Parameters.AddWithValue("@Depozite", DepoziteBtn.Text);
cnd.Parameters.AddWithValue("@Raporte", TextBox2.Text);
cnd.ExecuteNonQuery();
Response.Redirect("Delete.aspx");
con.Close();
}
catch (Exception ex)
{
Response.Write(ex);
}
}