Friday, May 27, 2011

Rowdatabound and Rowcommand

&ltColumns&gt
&ltasp:TemplateField&gt
&ltItemTemplate&gt
&ltasp:Button ID="btnstatus" runat="server" CommandArgument='&lt%#DataBinder.Eval(Container.DataItem,"RegId") %&gt' CommandName="RStatus" /&gt
&ltasp:Button ID="btndelete" runat="server" Text="Delete" CommandArgument='&lt%#DataBinder.Eval(Container.DataItem,"RegId") %&gt' CommandName="del"/&gt
&lt/ItemTemplate&lt
&lt/asp:TemplateField&gt
&lt/Columns&gt


Event call on code behind page





protected void dtldetail_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "RStatus")
{
int i = Int32.Parse(e.CommandArgument.ToString().Trim());
string str = "update member_reg set status=1 where regid= " + i + " ";
SqlConnection con5 = new SqlConnection(ConfigurationManager.AppSettings["Forumcon"].ToString().Trim());
SqlCommand cmd = new SqlCommand(str, con5);
cmd.CommandType = CommandType.Text;
con5.Open();
cmd.ExecuteNonQuery();
con5.Close();
filldatalist();
}
else if (e.CommandName == "del")
{
int j = Int32.Parse(e.CommandArgument.ToString().Trim());
string str = "delete member_reg where regid= " + j + " ";
SqlConnection con3 = new SqlConnection(ConfigurationManager.AppSettings["Forumcon"].ToString().Trim());
SqlCommand cmd = new SqlCommand(str, con3);
cmd.CommandType = CommandType.Text;
con3.Open();
int i=cmd.ExecuteNonQuery();
con3.Close();
filldatalist();
}
}
protected void dtldetail_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label _RegID = (Label)e.Row.FindControl("lblregid");
Label _lblStatus = (Label)e.Row.FindControl("lblStatus");
Button _btnstatus = (Button)e.Row.FindControl("btnstatus");
if (_lblStatus.Text == "1")
{
_btnstatus.Text = "Approve";
}
else
{
_btnstatus.Text = "Unapprove";
}
}
}
}

No comments:

Post a Comment