TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
dhoni kholi
NA
198
42.8k
How to Hide Button In Gridview After Click
Jan 25 2020 8:43 AM
This is my Code
How to Hide De Active Buttons
<
asp:GridView
ID
=
"GridView1"
runat
=
"server"
AutoGenerateColumns
=
"false"
DataKeyNames
=
"id"
>
<
Columns
>
<
asp:BoundField
DataField
=
"id"
HeaderText
=
"id"
/>
<
asp:BoundField
DataField
=
"username"
HeaderText
=
"Name"
/>
<
asp:TemplateField
>
<
ItemTemplate
>
<
div
class
=
"btn btn-warning fa fa-check"
>
<
asp:Button
ID
=
"btnChangeStatus"
runat
=
"server"
OnClick
=
"ChangeStatus"
Text
=
'<%# Eval("Status").ToString() == "True" ? "Active" : "De Activate" %>'
BackColor
=
"Transparent"
BorderWidth
=
"0"
/>
</
div
>
</
ItemTemplate
>
</
asp:TemplateField
>
</
Columns
>
</
asp:GridView
>
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!
this
.IsPostBack)
{
this
.Populate();
}
}
private
void
Populate()
{
string
constr = ConfigurationManager.ConnectionStrings[
"dbcon1"
].ConnectionString;
using
(SqlConnection con =
new
SqlConnection(constr))
{
using
(SqlCommand cmd =
new
SqlCommand(
"SELECT * FROM loguser"
, con))
{
using
(SqlDataAdapter da =
new
SqlDataAdapter(cmd))
{
DataSet ds =
new
DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
}
}
protected
void
ChangeStatus(
object
sender, EventArgs e)
{
string
constr = ConfigurationManager.ConnectionStrings[
"dbcon1"
].ConnectionString;
Button btn = sender
as
Button;
GridViewRow row = btn.NamingContainer
as
GridViewRow;
int
userId = Convert.ToInt32(
this
.GridView1.DataKeys[row.RowIndex].Value);
using
(SqlConnection con =
new
SqlConnection(constr))
{
using
(SqlCommand cmd =
new
SqlCommand(
"UPDATE loguser SET Status = @Status WHERE id = @UserId"
, con))
{
cmd.Parameters.AddWithValue(
"@Status"
, btn.Text ==
"Active"
? 0 : 1);
cmd.Parameters.AddWithValue(
"@UserId"
, userId);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
Response.Redirect(Request.Url.AbsoluteUri);
}
}
}
Output
My Status is flase or '0' Hide button
How to hide Deactive Status Button
Reply
Answers (
2
)
Validate dropdown in bootstrap multistep form
How to check particular table in datatable in c#