I have a GridView data like that.
When any row is updated once, then this specific row should be read only for 1 hour and Edit button also must be invisible for 1 hour.
How to get solution plz
HTML
<div class="table-responsive">
<asp:GridView ID="GridView1" runat="server" AllowPaging="false" CssClass="table table-striped table-bordered table-hover"
Font-Bold="true" Font-Names="Jameel Noori Nastaleeq" Font-Size="14" AutoGenerateColumns="false"
RowStyle-Wrap="true" HeaderStyle-Wrap="false" HeaderStyle-BackColor="#3AC0F2"
HeaderStyle-ForeColor="White" RowStyle-BackColor="#A1DCF2" AlternatingRowStyle-BackColor="White"
RowStyle-ForeColor="#3A3A3A" OnRowDataBound="OnRowDataBound" OnRowCancelingEdit="GridView1_RowCancelingEdit"
OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:TemplateField HeaderText="Choose Ans">
<EditItemTemplate>
<asp:DropDownList ID="ddlRemarks" class="form-control" runat="server">
<asp:ListItem>A</asp:ListItem>
<asp:ListItem>B</asp:ListItem>
<asp:ListItem>C</asp:ListItem>
<asp:ListItem>D</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="آپشن ڈی">
<ItemTemplate>
<asp:Label ID="lbl_QuestionD" runat="server" Text='<%# Bind("OpDU") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="آپشن سی">
<ItemTemplate>
<asp:Label ID="lbl_QuestionC" runat="server" Text='<%# Bind("OpCU") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="آپشن بی">
<ItemTemplate>
<asp:Label ID="lbl_QuestionB" runat="server" Text='<%# Bind("OpBU") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="آپشن اے">
<ItemTemplate>
<asp:Label ID="lbl_QuestionA" runat="server" Text='<%# Bind("OpAU") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="سوال">
<ItemTemplate>
<asp:Label ID="lbl_Question" runat="server" Text='<%# Bind("QuestionU") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Code">
<ItemTemplate>
<asp:Label ID="lbl_Code" runat="server" Text='<%# Bind("QID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
Code
C#
protected void ddlType_SelectedIndexChanged(object sender, EventArgs e)
{
BindGridQ();
}
private void BindGridQ()
{
con = new SqlDbConnect();
con.SqlQuery("select QID, QuestionU, OpAU, OpBU, OpCU, OpDU, OptionA from tblQuestionCreate where ClassID=@CID and SubjectID=@SID and QTypeID= @TID order by QID asc;");
con.Cmd.Parameters.Add(new SqlParameter("@CID", ddlClass.SelectedValue.ToString()));
con.Cmd.Parameters.Add(new SqlParameter("@SID", ddlSubjects.SelectedValue.ToString()));
con.Cmd.Parameters.Add(new SqlParameter("@TID", ddlType.SelectedValue.ToString()));
adapt.SelectCommand = con.Cmd;
adapt.Fill(sTable);
if (sTable.Rows.Count > 0)
{
GridView1.Visible = true;
GridView1.DataSource = sTable;
GridView1.DataBind();
// GridView1.Rows[i].BackColor = System.Drawing.Color.Yellow;
}
else
{
GridView1.Visible = false;
Response.Write("No Record Found");
return;
}
con.conClose();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
this.BindGrid();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
this.BindGrid();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
Label Code = (Label)GridView1.Rows[e.RowIndex].FindControl("lbl_Code");
DropDownList ddlRemarks = GridView1.Rows[e.RowIndex].FindControl("ddlRemarks") as DropDownList;
con = new SqlDbConnect();
con.SqlQuery("Update tblQuestionCreate set OptionA=@Status where QID=@No");
con.Cmd.Parameters.Add(new SqlParameter("@No", Code.Text));
con.Cmd.Parameters.Add(new SqlParameter("@Status", ddlRemarks.SelectedItem.Text));
con.NonQueryEx();
con.conClose();
GridView1.EditIndex = -1;
this.BindGrid();
//ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Answer Updated');", true);
}