<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnstatus" runat="server" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"RegId") %>' CommandName="RStatus" />
<asp:Button ID="btndelete" runat="server" Text="Delete" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"RegId") %>' CommandName="del"/>
</ItemTemplate<
</asp:TemplateField>
</Columns>
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