郭涛参演的电影:ASP.NET Codebehind模式下 Radiobutton控件 如何触发对数据库的添加事件?

来源:百度文库 编辑:中科新闻网 时间:2024/04/29 09:37:11
我想用三个RadioButton控件 来分别实现 对数据库的增 删 改 功能.可是我在Codebehind模式下 代码这么写 运行没有出错 可是无论选择 哪个控件页面上都不显示任何东西 而去掉对操作的判断 单独做增 删 改的操作却可以正常显示 这是为什么啊?我哪里写错了 应该怎么写 请大家指教。程序如下!
string strConnection="server=(local);database=pubs;user id=sa;password=loveshop";

if(RadioButton1.Checked==true){

string queryStr="select * from authors";
SqlConnection nwConn=new SqlConnection(strConnection);
DataSet admsSet=new DataSet();
SqlDataAdapter authorsAdapter=new SqlDataAdapter(queryStr,nwConn);
authorsAdapter.Fill(admsSet,"Authors");
DataRow authorsRow=admsSet.Tables["authors"].NewRow();
authorsRow["au_id"]="444-66-7777";
authorsRow["au_lname"]="Eson";
authorsRow["au_fname"]="zhang";
authorsRow["phone"]="999 888-6666";
authorsRow["contract"]=1;
admsSet.Tables["authors"].Rows.Add(authorsRow);
SqlCommandBuilder authorsBuilder=new SqlCommandBuilder(authorsAdapter);
authorsAdapter.InsertCommand=authorsBuilder.GetInsertCommand();
authorsAdapter.Update(admsSet,"Authors");
admsSet.Clear();
authorsAdapter.Fill(admsSet,"Authors");
admsGrid.DataSource=admsSet;
admsGrid.DataBind();
}

....
就是不知道这些事件如何写的 才来这寻求帮助

可悲哀的是 有的人却偏偏扯到老远去.
代码部分:
public void RadioButton1_CheckedChanged(object sender, System.EventArgs e)
{ //这部分写入选种RadioButton后要执行的代码

}

页面部分代码:
加入一个单击事件
<INPUT id="Button1" type="button" value="提交" name="Button1" runat="server" onserverclick="RadioButton1_CheckedChanged"></P>

asp.net下的控件都是基于事件响应的,从你的这段代码中,我看不到事件响应的写法……也许你应该从头学起。