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
dynamically Add Linkbutton To Delete row in Gridview
Jan 5 2020 3:58 AM
How to Delete Row in datatable Dynamically created in Gridview
This my code
<
asp:GridView
ID
=
"GVShowdata"
runat
=
"server"
RowStyle-Wrap
=
"False"
BackColor
=
"White"
BorderColor
=
"#999999"
BorderStyle
=
"None"
BorderWidth
=
"1px"
CellPadding
=
"3"
onrowdatabound
=
"GVShowdata_RowDataBound"
onrowcommand
=
"GVShowdata_RowCommand"
onrowdeleting
=
"GVShowdata_RowDeleting"
CssClass
=
"GridHeader"
GridLines
=
"Vertical"
>
<
AlternatingRowStyle
BackColor
=
"#DCDCDC"
/>
<
FooterStyle
BackColor
=
"#CCCCCC"
ForeColor
=
"Black"
/>
<
HeaderStyle
BackColor
=
"#000084"
Font-Bold
=
"True"
ForeColor
=
"White"
/>
<
PagerStyle
BackColor
=
"#999999"
ForeColor
=
"Black"
HorizontalAlign
=
"Center"
/>
<
RowStyle
Wrap
=
"False"
BackColor
=
"#EEEEEE"
ForeColor
=
"Black"
>
</
RowStyle
>
<
SelectedRowStyle
BackColor
=
"#008A8C"
Font-Bold
=
"True"
ForeColor
=
"White"
/>
<
SortedAscendingCellStyle
BackColor
=
"#F1F1F1"
/>
<
SortedAscendingHeaderStyle
BackColor
=
"#0000A9"
/>
<
SortedDescendingCellStyle
BackColor
=
"#CAC9C9"
/>
<
SortedDescendingHeaderStyle
BackColor
=
"#000065"
/>
</
asp:GridView
>
protected
void
GVShowdata_RowDataBound(
object
sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
e.Row.Cells[0].Visible =
false
;
e.Row.Cells[1].Visible =
false
;
e.Row.Cells[2].Visible =
false
;
e.Row.Cells[3].Visible =
false
;
e.Row.Cells[4].Visible =
false
;
e.Row.Cells[5].Visible =
false
;
e.Row.Cells[6].Visible =
false
;
e.Row.Cells[7].Visible =
false
;
e.Row.Cells[8].Visible =
false
;
e.Row.Cells[9].Visible =
false
;
e.Row.Cells[16].Visible =
false
;
e.Row.Cells[17].Visible =
false
;
e.Row.Cells[18].Visible =
false
;
e.Row.Cells[19].Visible =
false
;
e.Row.Cells[20].Visible =
false
;
e.Row.Cells[21].Visible =
false
;
e.Row.Cells[22].Visible =
false
;
e.Row.Cells[26].Visible =
false
;
e.Row.Cells[27].Visible =
false
;
e.Row.Cells[10].Attributes[
"width"
] =
"150px"
;
e.Row.Cells[11].Attributes[
"width"
] =
"75px"
;
e.Row.Cells[12].Attributes[
"width"
] =
"75px"
;
e.Row.Cells[13].Attributes[
"width"
] =
"75px"
;
e.Row.Cells[14].Attributes[
"width"
] =
"50px"
;
e.Row.Cells[15].Attributes[
"width"
] =
"50px"
;
e.Row.Cells[23].Attributes[
"width"
] =
"75px"
;
e.Row.Cells[24].Attributes[
"width"
] =
"75px"
;
e.Row.Cells[25].Attributes[
"width"
] =
"75px"
;
e.Row.Cells[28].Attributes[
"width"
] =
"150px"
;
if
(e.Row.DataItem !=
null
)
{
LinkButton lb =
new
LinkButton();
lb.CommandArgument = e.Row.Cells[29].Text;
lb.CommandName =
"Delete"
;
lb.Text =
"Delete"
;
e.Row.Cells[29].Controls.Add((Control)lb);
}
}
protected
void
GVShowdata_RowCommand(
object
sender, GridViewCommandEventArgs e)
{
if
(e.CommandName ==
"Delete"
)
{
GridViewRow gvr = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
int
RemoveAt = gvr.RowIndex;
DataTable dt =
new
DataTable();
dt = (DataTable)ViewState[
"Records"
];
dt.Rows.RemoveAt(RemoveAt);
dt.AcceptChanges();
ViewState[
"Records"
] = dt;
}
}
protected
void
GVShowdata_RowDeleting(
object
sender, GridViewDeleteEventArgs e)
{
GVShowdata.DataSource = ViewState[
"Records"
];
GVShowdata.DataBind();
}
Output
When I click Delete Link button
That cell Only remove
Please Help me to How to remove Full row
Reply
Answers (
6
)
how to show one row from multiple rows with one column havin
Making a single row with comma separated list in mvc