发布网友 发布时间:2024-10-24 02:59
共2个回答
热心网友 时间:2024-11-08 14:16
首先处理数据库,代码如下:(本人数据库验证为:登陆名sa,密码123456)
create database radio_txt
go
use radio_txt
go
create table left_right
(
left_info varchar(100),
right_info varchar(100)
)
前台代码:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.txtLeft.Visible = true;
this.txtRight.Visible = true;
}
if (this.rbtnLeft.Checked)
{
this.txtLeft.Text = this.txtRight.Text.ToString();
this.txtRight.Visible = false;
this.txtLeft.Visible = true;
}
if (this.rbtnRight.Checked)
{
this.txtRight.Text = this.txtLeft.Text.ToString();
this.txtLeft.Visible = false;
this.txtRight.Visible = true;
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
string info_left = this.txtLeft.Text.ToString();
string info_right = this.txtRight.Text.ToString();
SqlConnection con = new SqlConnection("server=;database=radio_txt;user=sa;pwd=123456;");
con.Open();
if (this.rbtnLeft.Checked)
{
SqlCommand cmd = new SqlCommand("insert into left_right values('" + info_left + "','')", con);
cmd.ExecuteNonQuery();
}
else
{
SqlCommand cmd = new SqlCommand("insert into left_right values('','" + info_right + "')", con);
cmd.ExecuteNonQuery();
}
}
}
界面如图:其中两个RadioButton的ID属性改为rbtnLeft、rbtnRight,GroupName属性改为Left_Right,AutoPostBack属性改为true;两个TextBox的ID属性改为txtLeft、txtRight;Button的ID属性改为btnSubmit,Text属性改为提交。
热心网友 时间:2024-11-08 14:17
很好做啊。。。就是把左右需要实现隐藏功能的控件放进<panel>标记里就是了。如点击右边的radio button 你写个CheckedChanged事件啊把<panel>的Visible设置为false 就是隐藏了撒,不懂可以HI我