2013-12-13 142 views
1
protected void GVPaperrate_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 

    DataTable dtbirdtype = new DataTable(); 
    objRetailPL.status = 5; 
    dtbirdtype = objRetailBAL.GetType(objRetailPL); 


    DropDownList ddl1 = (DropDownList)e.Row.FindControl("ddlType"); 
    if (ddl1 != null) 
    { 
     ddl1.DataSource = dtbirdtype; 
     ddl1.DataTextField = "birdname"; 
     ddl1.DataValueField = "sno"; 
     ddl1.DataBind(); 
     ddl1.Items.Add(new ListItem("--Select--", "0")); 
     ddl1.SelectedIndex = ddl1.Items.Count - 1; 
    } 
    DataTable dtzonedet = new DataTable(); 
    dtzonedet = objRetailBAL.GetZoneDet(); 
    DropDownList ddlzone = (DropDownList)e.Row.FindControl("ddlzone"); 
    if (ddlzone != null) 
    { 
     ddlzone.DataSource = dtzonedet; 
     ddlzone.DataTextField = "ZoneName"; 
     ddlzone.DataValueField = "SNo"; 
     ddlzone.DataBind(); 
     ddlzone.Items.Add(new ListItem("--Select--","0")); 
     ddlzone.SelectedIndex=ddlzone.Items.Count-1; 

    } 
}protected void btngo_Click(object sender, ImageClickEventArgs e) 
{ 
    DataTable dtinsert = new DataTable(); 
    objRetailPL.ZoneName = txtzone.Text.ToString(); 
    objRetailPL.Username = Session["Username"].ToString(); 

    dtinsert = objRetailBAL.InsertZone(objRetailPL); 
    if (dtinsert.Rows.Count > 0) 
    { 
     if (dtinsert.Rows[0]["status"].ToString() == "2") 
     { 
      ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "insert", "alert('Saved Successfully')", true); 
      //GVPaperrate.DataBind(); 
      txtzone.Text = ""; 
     } 
     else if (dtinsert.Rows[0]["status"].ToString() == "1") 
     { 
      ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "insert", "alert('ZoneName Already Exists')", true); 
     } 
    } 
    else 

    { 
     ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "insert", "alert('Insertion Failed Please Consult IT Department')", true); 
    } 
} 

如何調用按鈕中的RowDataBound單擊event.I想要的結果就好像點擊去按鈕它會自動顯示輸​​入的數據在dropdownlist.But我沒有那樣。我必須做的,請幫助我。如何在asp.net中的Button Click事件中調用RowDataBound事件?

+0

你想要gridview按鈕點擊事件? –

回答

0

我想你是在數據庫中插入數據。插入獲取數據並使用gridview綁定後。

試試這個, GVPaperrate.DataBind(); 爲什麼你評論這條線。你應該取消註釋這將起作用。

您的按鈕上單擊代碼

protected void btngo_Click(object sender, ImageClickEventArgs e) 
    { 
    DataTable dtinsert = new DataTable(); 
    objRetailPL.ZoneName = txtzone.Text.ToString(); 
    objRetailPL.Username = Session["Username"].ToString(); 

    dtinsert = objRetailBAL.InsertZone(objRetailPL); 
    if (dtinsert.Rows.Count > 0) 
    { 
     if (dtinsert.Rows[0]["status"].ToString() == "2") 
     { 
      ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "insert", "alert('Saved Successfully')", true); 
      **GVPaperrate.DataBind()**; //why you comment this 
      txtzone.Text = ""; 
     } 
     else if (dtinsert.Rows[0]["status"].ToString() == "1") 
     { 
      ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "insert", "alert('ZoneName Already Exists')", true); 
     } 
    } 
    else 

    { 
    ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "insert", "alert('Insertion Failed Please Consult IT Department')", true); 
    } 
    } 
0

綁定Go按鈕的點擊或bind()方法上Page_PreRender電網後電網。

相關問題