HTML:
<asp:GridView ID="GridView1" runat="server" Height="100px" Width="100%" OnPageIndexChanging="GridView1_PageIndexChanging" DataKeyNames="Id"
AutoGenerateColumns="False" AllowPaging="True" PageSize="8" >
<Columns>
<asp:BoundField DataField="id" HeaderText="ID" SortExpression="id" Visible="false"></asp:BoundField>
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:ImageButton ID="lnkdelete" ImageUrl="~/Images/del.png" Width="20" Height="20" runat="server" OnClick="lnkdelete_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
C#:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindGrid();
}
}
private void BindGrid()
{
SELECT Name FROM Table1 WHERE (Type = 'T-01') OR (Type = 'T-02') and DeletionDate is null";
this.GridView1.DataSource = DataManager.DatabaseManager.GetOrCreateConnection(DataManager.DatabaseManager.ConnectionType.MySQL).GetData(query);
GridView1.DataBind();
}
protected void lnkdelete_Click(object sender, ImageClickEventArgs e)
{
ImageButton lnkbtn = sender as ImageButton;
//getting particular row linkbutton
GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
//getting id of particular row
int id = Convert.ToInt32(GridView1.DataKeys[gvrow.RowIndex].Value.ToString());
string user = (string)(Session["UserAuthentication"]);
string CommandText = "UPDATE Table1 SET DeletionDate = SYSDATE() WHERE Id = '" + id + "'";
DataManager.DatabaseManager.GetOrCreateConnection(DataManager.DatabaseManager.ConnectionType.MySQL).ExecuteScalerCommand(CommandText, null);
}
Database Table:
Id
|
Name
|
Type
|
Location
|
DeletionDate
|
1
|
A
|
T-01
|
abc
|
|
2
|
B
|
T-02
|
pqr
|
|
3
|
C
|
T-02
|
xyz
|
|
4
|
D
|
T-02
|
abc
|
|
5
|
E
|
T-03
|
pqr
|
|
On deleting any Gridview row, using "Delete" Image button of Gridview, "system date" is updated in Database "DeletionDate" column for that particular row.
and while Gridbind, column whose "DeletionDate is null" are only shown inside Gridview.
Problem is: when I delete any Gridview row, its deletion date is saved in Database table,
but dispite of using "DeletionDate is null" in GridBind query, that deleted row shows in Grdiview.
Is Gridbind query is wrong??
Please reply what is the problem?