本文介绍了如何通过单击单选按钮启用文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
首先,我在页面加载时禁用了文本框,单击单选按钮后我要启用它,并且必须将单选按钮的单击值存储在数据库中.
first i have disabled textbox on page load, after clicking on radiobutton i want enable it and have to store clicked value of radio button in database
推荐答案
public partial class RadioButton : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Enabled = false;
}
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
TextBox1.Enabled = true;
TextBox1.Text = "I Am Male";
string value = RadioButton1.Text;
SqlConnection sqlconn = new SqlConnection("server=.\\sqlexpress;database=practice;integrated security=true;");
SqlCommand sqlcomm = new SqlCommand("insert into insertvalue(radiobtnvalue) values(@a)", sqlconn);
sqlconn.Open();
sqlcomm.Parameters.Add("@a", SqlDbType.VarChar, 10).Value = value.ToString();
sqlcomm.ExecuteNonQuery();
sqlconn.Close();
Response.Write("Value Saved");
}
}
来源-
Source-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RadioButton.aspx.cs" Inherits="RadioButton" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
.style1
{
width: 100%;
}
.style2
{
width: 87px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="style1">
<tr>
<td class="style2">
Select Value</td>
<td>
<asp:RadioButton ID="RadioButton1" runat="server" AutoPostBack="True"
oncheckedchanged="RadioButton1_CheckedChanged" Text="Male" />
</td>
</tr>
<tr>
<td class="style2">
Name</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
SQL部分-
Sql part-
create table insertvalue(radiobtnvalue varchar(10))
select * from insertvalue
这篇关于如何通过单击单选按钮启用文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!