Sunday, September 5, 2010

Gridview RowCommand

If you hav any button inside Gridview you handle that button under RowCommand like here Gridview have a Insert button inside Grid.

 protected void gvStuDetails_RowCommand(object sender, GridViewCommandEventArgs e)  
{
if (e.CommandName.Equals("Insert"))
{
objStuCls.StuId = Convert.ToInt32(((DropDownList)gvStuDetails.FooterRow.FindControl("ddlNewStuId")).SelectedValue);
objStuCls.StuName = Convert.ToString(((TextBox)gvStuDetails.FooterRow.FindControl("txtNewStuName")).Text);
try
{
int int = objClassMasterBLL.InsertClassMaster(objStuCls);
if (int > 0)
{
msgText = "Record Added Successfully !";
gvStuDetails.EditIndex = -1;
gvStu();
}
else
{
msg.Text = "This record already exists !";
}
}
catch (Exception ee)
{
msg.Text = ee.Message.ToString();
}
}
}

Thanks & Regards
Santosh

0 comments:

Post a Comment