单选按钮在asp.net中不起作用

时间:2013-04-04 10:21:12

标签: asp.net

我是初学者.radio按钮无法正常工作。我不知道什么是问题

protected void RadioButton1_CheckedChanged1(object sender, EventArgs e)
{
    if (RadioButton1.Checked == true)
    {
        Label1.Text = "Upload our video file";
        RadioButton2.Checked = false;
    }
    else
    {
        Label1.Text = "Upload our image file";
        RadioButton1.Checked = false;
    }
}
public void upload()
{
    SqlCommand cmd = new SqlCommand("insert into video_info(Name,path,user_name,email,comment)values(@Name,@path,@user_name,@email,@comment)", con);
    cmd.Parameters.AddWithValue("@Name", txt_file.Text);
    cmd.Parameters.AddWithValue("@path", "video/" + fileuplod.FileName);
    cmd.Parameters.AddWithValue("@user_name", use_name.Text);
    cmd.Parameters.AddWithValue("@email", email.Text);
    cmd.Parameters.AddWithValue("@comment", comment.Text);
    fileuplod.SaveAs(Server.MapPath("~/video/" + fileuplod.FileName));
    cmd.ExecuteNonQuery();
}
protected void submit_Click(object sender, EventArgs e)
{
    upload();
}

}

我想做什么。我有两个单选按钮。图像和视频。假设用户选择图像。然后所有细节将保存在图像表中或用户点击视频。所有细节都将转到image_database。

可能是我的逻辑错误。

2 个答案:

答案 0 :(得分:2)

在radiobutton属性中将自动回发设置为true

答案 1 :(得分:1)

Try this 
public void upload(string query)
{
    SqlCommand cmd = new SqlCommand(query, con);
    cmd.Parameters.AddWithValue("@Name", txt_file.Text);
    cmd.Parameters.AddWithValue("@path", "video/" + fileuplod.FileName);
    cmd.Parameters.AddWithValue("@user_name", use_name.Text);
    cmd.Parameters.AddWithValue("@email", email.Text);
    cmd.Parameters.AddWithValue("@comment", comment.Text);
    fileuplod.SaveAs(Server.MapPath("~/video/" + fileuplod.FileName));
    cmd.ExecuteNonQuery();
}
protected void submit_Click(object sender, EventArgs e)
{
 string query;
if (RadioButton1.Checked == true)
    {

       query="insert into video_info(Name,path,user_name,email,comment)values(@Name,@path,@user_name,@email,@comment)";
       Label1.Text = "Upload our video file";
        RadioButton2.Checked = false;
    }
    else
    {

       query="insert into Image_info(Name,path,user_name,email,comment)values(@Name,@path,@user_name,@email,@comment)";
       Label1.Text = "Upload our image file";
        RadioButton1.Checked = false;
    }
  if(query!="")
    {
       upload(query);
    }

}