2013-04-04 350 views
-1

我是beginner.radio按鈕,無法正常工作。我dn't知道什麼是一個問題單選按鈕在asp.net中不工作

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(); 
} 

}

我想要做,我有兩個無線電button.Image和video.Suppose用戶選擇image.then所有細節將節省圖像是什麼表或用戶點擊video.All細節去image_database。

可能是我的邏輯錯誤。

+0

什麼是「不正常」?你期望發生什麼,發生了什麼? – CodeCaster 2013-04-04 10:31:57

+0

prob --- ****兩個單選按鈕都檢查***值不插入到不同的表 – 2013-04-04 10:34:46

+0

thnx球員的幫助.... *我固定d錯誤,使用組功能來分組兩個單選按鈕* – 2013-04-05 14:39:34

回答

2

把自動回發到真正的單選按鈕屬性

+0

我我已經設置 – 2013-04-04 10:30:19

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); 
    } 

} 
+0

thnx的幫助,但數據庫如何知道什麼是視頻路徑和圖像path.becoz你可以不使用圖像路徑或文件.....顯示錯誤的字符串查詢(值沒有分配) – 2013-04-04 10:47:39

+0

因爲你必須使用fileuploade控制。 – 2013-04-04 10:57:10