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);
}
}
如何在按钮单击事件中调用行数据绑定。我想要的结果,如果单击go按钮,它将自动在下拉列表中显示输入的数据。但我不是那样的。我必须做什么请帮助我。
单击Go按钮后绑定网格或在Page_PreRender((方法上绑定网格。
我认为您正在数据库中插入数据。插入后获取数据并与网格视图绑定。
试试这个, 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);
}
}