This is my child grid(inner grid)
protected void ParameterGv_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridViewRow row = (GridViewRow)((Control)e.CommandSource).Parent.Parent;
GridView gv = (GridView)(e.CommandSource);
int i = Convert.ToInt32(e.CommandArgument);
GridViewRow Childrow = gv.Rows[i];
if (e.CommandName == "Edit")
{
}
}
protected void ParameterGv_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView gvtemp = (GridView)sender;
gvtemp.EditIndex = e.NewEditIndex;
FillmainGrid();
}
edit row command firing but update cancel is not coming again edit is comming
<asp:GridView ID="HeaderGv" runat="server" AutoGenerateColumns="False" OnRowDataBound="HeaderGv_RowDataBound" Width="100%" DataKeyNames="PARAM_HEAD_ID" ShowFooter="true">
<Columns>
<asp:TemplateField HeaderText="SNO">
<ItemTemplate>
<asp:Label ID="SNOLbl" runat="server" Text='<%#Eval("SNO") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="ADDBtn" runat="server" onclick="ADDBtn_Click" Text="ADD" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Group">
<ItemTemplate>
<asp:Label ID="GroupLbl" runat="server" Text='<%# Eval("PARAM_HEAD_NAME") %>'></asp:Label>
<asp:GridView ID="ParameterGv" runat="server" Width="100%" OnRowDataBound="ParameterGv_RowDataBound"
HeaderStyle-CssClass="grid_col_head" AutoGenerateColumns="False"
onrowcancelingedit="ParameterGv_RowCancelingEdit"
onrowediting="ParameterGv_RowEditing"
onrowupdating="ParameterGv_RowUpdating" DataKeyNames="PARAM_SUB_ID"
onrowcommand="ParameterGv_RowCommand">
<Columns>
<asp:BoundField DataField="SNO" ItemStyle-Width="15" HeaderText="SNO" >
<ItemStyle Width="15px" />
</asp:BoundField>
<asp:BoundField DataField="PARAM_HEAD_ID" HeaderText="PARAM ID" />
<asp:BoundField DataField="PARAM_SUB_ID" HeaderText="PARAMSUBID" />
<asp:BoundField DataField="PARAM_SUB_NAME" HeaderText="PARAM SUB NAME" ReadOnly="false"/>
<asp:TemplateField HeaderText="Results Of Verification">
<ItemTemplate>
<asp:DropDownList ID="ResultsDdl" runat="server">
<asp:ListItem>--select--</asp:ListItem>
<asp:ListItem>yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
<asp:ListItem>NA</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ResultsDdl" runat="server">
<asp:ListItem>--select--</asp:ListItem>
<asp:ListItem>yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
<asp:ListItem>NA</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Details oF Audit Findings">
<ItemTemplate>
<asp:DropDownList ID="FindingsDdl" runat="server">
<asp:ListItem>--select--</asp:ListItem>
<asp:ListItem>yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
<asp:ListItem>NA</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="FindingsDdl" runat="server">
<asp:ListItem>--select--</asp:ListItem>
<asp:ListItem>yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
<asp:ListItem>NA</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Rectified by Audit Team">
<ItemTemplate>
<asp:DropDownList ID="RectifiedDdl" runat="server">
<asp:ListItem>--select--</asp:ListItem>
<asp:ListItem>yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
<asp:ListItem>NA</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="RectifiedDdl" runat="server">
<asp:ListItem>--select--</asp:ListItem>
<asp:ListItem>yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
<asp:ListItem>NA</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="Edit" ShowEditButton="true"/>
</Columns>
<HeaderStyle CssClass="grid_col_head" />
</asp:GridView>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ResultsoneDdl" runat="server">
<asp:ListItem>--Select--</asp:ListItem>
<asp:ListItem>Yes</asp:ListItem>
<asp:ListItem>NO</asp:ListItem>
<asp:ListItem>N/A</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="PARAM_HEAD_ID" HeaderText="HeaderID"
ReadOnly="True" />
</Columns>
</asp:GridView>
public partial class AuditCheckList : System.Web.UI.Page
{
DataTable ForDdl;
#region Logger Setup
protected static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
DCCheckList objdc = new DCCheckList();
BLCkeckList objbl = new BLCkeckList();
protected void Page_Load(object sender, EventArgs e)
{
Session["UserId"] = 101;
Session["RoleId"] = 201;
Session["RoleName"] = "admin";
objdc.auditphase = Request.QueryString["AuditPhase"];
objdc.auditorname = Request.QueryString["AuditorName"];
objdc.branch = Request.QueryString["Branch"];
objdc.ActualStartDate = Request.QueryString["ActualStartDate"];
if (Session["UserId"] != null && Session["RoleId"] != null && Session["RoleName"] != null)
{
if (!IsPostBack)
{
NameLbl.Text = Request.QueryString["AuditorName"];
DateLbl.Text = Request.QueryString["ActualStartDate"];
BranchLbl.Text = Request.QueryString["Branch"];
FillmainGrid();
}
}
else
{
Session.Abandon();
Response.Redirect("~/Login.aspx");
}
}
private void FillmainGrid()
{
DataTable dt = new DataTable();
dt = objbl.BindmainGrid();
HeaderGv.DataSource = dt;
HeaderGv.DataBind();
}
protected void HeaderGv_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridViewRow row = e.Row;
if (e.Row.RowType != DataControlRowType.Pager)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[0].Visible = false;
e.Row.Cells[1].Visible = false;
e.Row.Cells[2].Visible = false;
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[1].ForeColor = System.Drawing.Color.FromArgb(153, 0, 0);
e.Row.Cells[1].BackColor = Color.FromArgb(221, 221, 221);
e.Row.Cells[1].Font.Size = 12;
e.Row.Cells[1].Font.Name = "Century";
e.Row.Cells[1].Visible = true;
e.Row.Cells[0].Visible = false;
e.Row.Cells[2].Visible = false;
}
}
if (row.DataItem == null)
{
return;
}
GridView gv = new GridView();
objdc.headerID = Convert.ToInt32(e.Row.Cells[2].Text);
gv = (GridView)row.Cells[1].FindControl("ParameterGv");
if (gv != null)
{
BindCheckList(gv, objdc.headerID);
}
}
private void BindCheckList(GridView gv, int p)
{
objdc.auditphase = Request.QueryString["AuditPhase"];
objdc.auditorname = Request.QueryString["AuditorName"];
objdc.branch = Request.QueryString["Branch"];
objdc.headerID = p;
ViewState["HeaderId"] = p;
DataTable dt = new DataTable();
dt = objbl.FillParametersGrid(ref objdc);
DataTable dt1 = new DataTable();
dt1 = objbl.getdata(ref objdc);
if (dt1.Rows.Count > 0)
{
ForDdl = dt1.Copy();
ForDdl.Columns.Remove("SNO");
ForDdl.Columns.Remove("PARAM_HEAD_ID");
ForDdl.Columns.Remove("PARAM_SUB_ID");
ForDdl.Columns.Remove("PARAM_SUB_NAME");
gv.DataSource = dt1;
gv.DataBind();
}
else
{
gv.DataSource = dt;
gv.DataBind();
}
}
protected void ParameterGv_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridViewRow row = e.Row;
e.Row.Cells[0].BackColor = Color.White;
e.Row.Cells[0].ForeColor = Color.Black;
e.Row.Cells[0].Font.Bold = false;
e.Row.Cells[0].Font.Size = 11;
e.Row.Cells[0].Font.Name = "calibri";
e.Row.Cells[3].BackColor = Color.White;
e.Row.Cells[3].ForeColor = Color.Black;
e.Row.Cells[3].Font.Bold = false;
e.Row.Cells[3].Font.Size = 11;
e.Row.Cells[3].Font.Name = "calibri";
e.Row.Cells[4].BackColor = Color.White;
e.Row.Cells[4].ForeColor = Color.Black;
e.Row.Cells[4].Font.Bold = false;
e.Row.Cells[4].Font.Size = 11;
e.Row.Cells[4].Font.Name = "calibri";
e.Row.Cells[5].BackColor = Color.White;
e.Row.Cells[5].ForeColor = Color.Black;
e.Row.Cells[5].Font.Bold = false;
e.Row.Cells[5].Font.Size = 11;
e.Row.Cells[5].Font.Name = "calibri";
e.Row.Cells[6].BackColor = Color.White;
e.Row.Cells[6].ForeColor = Color.Black;
e.Row.Cells[6].Font.Bold = false;
e.Row.Cells[6].Font.Size = 11;
e.Row.Cells[6].Font.Name = "calibri";
e.Row.Cells[7].BackColor = Color.White;
e.Row.Cells[7].Font.Bold = false;
e.Row.Cells[7].Font.Name = "calibri";
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[1].Visible = false;
e.Row.Cells[2].Visible = false;
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].Visible = true;
e.Row.Cells[1].Visible = false;
e.Row.Cells[2].Visible = false;
e.Row.Cells[3].Visible = true;
e.Row.Cells[4].Visible = true;
((DropDownList)row.Cells[4].FindControl("ResultsDdl")).Enabled = true;
((DropDownList)row.Cells[5].FindControl("FindingsDdl")).Enabled = true;
((DropDownList)row.Cells[6].FindControl("RectifiedDdl")).Enabled = true;
DataRowView drv = (DataRowView)e.Row.DataItem;
string Results = drv["RESULTSOFAUDIT"].ToString();
string Findings = drv["AUDITFINDINGS"].ToString();
string Rectified = drv["RECTIFICATIONS"].ToString();
DropDownList Resulddl = (DropDownList)e.Row.FindControl("ResultsDdl");
DropDownList Findddl = (DropDownList)e.Row.FindControl("FindingsDdl");
DropDownList Rectddl = (DropDownList)e.Row.FindControl("RectifiedDdl");
Resulddl.Items.FindByValue(Results).Selected = true;
Findddl.Items.FindByValue(Findings).Selected = true;
Rectddl.Items.FindByValue(Rectified).Selected = true;
}
}
protected void ParameterGv_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
e.Cancel = true;
HeaderGv.EditIndex = -1;
FillmainGrid();
}
protected void ParameterGv_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
GridViewRow row = (GridViewRow)HeaderGv.Rows[e.RowIndex];
GridView gv = (GridView)row.Cells[1].FindControl("ParameterGv");
objdc.auditphase = Request.QueryString["AuditPhase"];
objdc.auditorname = Request.QueryString["AuditorName"];
objdc.branch = Request.QueryString["Branch"];
objdc.parameterid = Convert.ToInt32(gv.Rows[e.RowIndex].Cells[2].Text);
objdc.headerID = Convert.ToInt32(gv.Rows[e.RowIndex].Cells[1].Text);
objdc.results = ((DropDownList)gv.Rows[e.RowIndex].Cells[4].FindControl("ResultsDdl")).SelectedItem.Text;
objdc.findings = ((DropDownList)gv.Rows[e.RowIndex].Cells[5].FindControl("FindingsDdl")).SelectedItem.Text;
objdc.Rectifications = ((DropDownList)gv.Rows[e.RowIndex].Cells[6].FindControl("RectifiedDdl")).SelectedItem.Text;
objdc.modifiedby = Session["RoleName"].ToString();
int result = objbl.updatechecklist(ref objdc);
if (result == 1)
{
Literal li = new Literal();
FillmainGrid();
li.Text = "<script>alert('Data Updated sucessfully');</script>";
Page.Controls.Add(li);
}
}
catch (Exception ex)
{
log.Error(ex.Message, ex);
}
}
protected void ParameterGv_RowEditing(object sender, GridViewEditEventArgs e)
{
FillmainGrid();
GridView gvtemp = (GridView)sender;
gvtemp.EditIndex = e.NewEditIndex;
}
protected void ParameterGv_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridViewRow row = (GridViewRow)((Control)e.CommandSource).Parent.Parent;
GridView gv = (GridView)(e.CommandSource);
int i = Convert.ToInt32(e.CommandArgument);
GridViewRow Childrow = gv.Rows[i];
if (e.CommandName == "Edit")
{
}
}
protected void ADDBtn_Click(object sender, EventArgs e)
{
try
{
int j = 0;
for (int i = 0; i < HeaderGv.Rows.Count; i++)
{
GridView gv = (GridView)HeaderGv.Rows[i].Cells[1].FindControl("ParameterGv");
for (int k = 0; k < gv.Rows.Count; k++)
{
objdc.auditphase = Request.QueryString["AuditPhase"];
objdc.auditorname = Request.QueryString["AuditorName"];
objdc.branch = Request.QueryString["Branch"];
objdc.parameterid = Convert.ToInt32(gv.Rows[k].Cells[2].Text);
objdc.headerID = Convert.ToInt32(gv.Rows[k].Cells[1].Text);
objdc.paramsubname = gv.Rows[k].Cells[3].Text;
objdc.headname = ((Label)HeaderGv.Rows[i].Cells[1].FindControl("GroupLbl")).Text;
objdc.results = ((DropDownList)gv.Rows[k].Cells[4].FindControl("ResultsDdl")).SelectedItem.Text;
objdc.findings = ((DropDownList)gv.Rows[k].Cells[5].FindControl("FindingsDdl")).SelectedItem.Text;
objdc.Rectifications = ((DropDownList)gv.Rows[k].Cells[6].FindControl("RectifiedDdl")).SelectedItem.Text;
objdc.insertedby = Session["RoleName"].ToString();
objdc.modifiedby = Session["RoleName"].ToString();
objbl.insertchecklist(ref objdc);
}
j = j + 1;
}
if (j == HeaderGv.Rows.Count)
{
Literal li = new Literal();
FillmainGrid();
HeaderGv.ShowFooter = false;
objbl.CloseAuditChecklist(ref objdc);
li.Text = "<script>alert('Data Saved Sucssfully');</script>";
Page.Controls.Add(li);
}
}
catch (Exception ex)
{
log.Error(ex.Message, ex);
}
}
protected void FreezeBtn_Click(object sender, EventArgs e)
{
objdc.auditphase = Request.QueryString["AuditPhase"];
objdc.auditorname = Request.QueryString["AuditorName"];
objdc.branch = Request.QueryString["Branch"];
objdc.modifiedby = Session["RoleName"].ToString();
objdc.formname = "Check List";
objdc.headername = "Content Of Report";
int result = objbl.UpdateStatus(ref objdc);
if (result == 1)
{
ViewState["STATUS"] = "freezed";
FillmainGrid();
Literal li = new Literal();
li.Text = "<script>alert('form freezed sucessfully');</script>";
FreezeBtn.Visible = false;
Page.Controls.Add(li);
}
else
{
Literal li = new Literal();
li.Text = "<script>alert('Please close this form before freezing it');</script>";
Page.Controls.Add(li);
}
}
}