更新行命令 [英] update Row command

查看:73
本文介绍了更新行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的子网格(内部网格)

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);
  //string s = gv.DataKeys[row.RowIndex][0].ToString();
  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>



公共局部类AuditCheckList:System.Web.UI.Page
{
DataTable ForDdl;
#region记录仪设置
受保护的静态只读log4net.ILog日志= log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
//为datacontainer类创建一个对象
DCCheckList objdc =新的DCCheckList();
//为业务层类创建对象
BLCkeckList objbl =新的BLCkeckList();
受保护的void Page_Load(对象发送者,EventArgs e)
{
会话["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)
{
如果(!IsPostBack)
{
NameLbl.Text = Request.QueryString ["AuditorName"];
DateLbl.Text = Request.QueryString ["ActualStartDate"];
BranchLbl.Text = Request.QueryString ["Branch"];
//此方法将数据绑定到gridview
FillmainGrid();

}
}
其他
{
Session.Abandon();
Response.Redirect(〜/Login.aspx");
}
}
私有void FillmainGrid()
{
DataTable dt = new DataTable();
dt = objbl.BindmainGrid();
HeaderGv.DataSource = dt;
HeaderGv.DataBind();

}
受保护的void HeaderGv_RowDataBound(对象发送者,GridViewRowEventArgs e)
{
GridViewRow行= e.Row;
如果(e.Row.RowType!= DataControlRowType.Pager)
{
如果(e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells [0] .Visible = false;
e.Row.Cells [1] .Visible = false;
e.Row.Cells [2] .Visible = false;
}
如果(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;
}
}
如果(row.DataItem == null)
{
返回;
}
GridView gv = new GridView();
objdc.headerID = Convert.ToInt32(e.Row.Cells [2] .Text);
gv =(GridView)row.Cells [1] .FindControl("ParameterGv");
如果(gv!= null)
{
BindCheckList(gv,objdc.headerID);
}
}
私有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 =新的DataTable();
dt1 = objbl.getdata(ref objdc);
如果(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();
}
其他
{
gv.DataSource = dt;
gv.DataBind();
}
}
受保护的void ParameterGv_RowDataBound(对象发送者,GridViewRowEventArgs e)
{//网格行数据绑定
GridViewRow行= 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";
如果(e.Row.RowType == DataControlRowType.Header)
{
//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;
//如果(ViewState ["STATUS"] ==冻结")
//{
//e.Row.Cells [7] .Visible = false;
//}
}
如果(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;
字符串结果= drv ["RESULTSOFAUDIT"].ToString();
字符串结果= drv ["AUDITFINDINGS"].ToString();
已校正的字符串= 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;

//如果(ViewState ["STATUS"].ToString()==冻结")
//{
//e.Row.Cells [7] .Visible = false;
//}

}
}
受保护的void ParameterGv_RowCancelingEdit(对象发送者,GridViewCancelEditEventArgs e)
{//子网格行取消事件
e.Cancel = true;
HeaderGv.EditIndex = -1;
FillmainGrid();

}
受保护的void ParameterGv_RowUpdating(对象发送者,GridViewUpdateEventArgs e)
{//子网格行更新
试试
{
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.headname = HeaderGv.Rows [e.RowIndex] .Cells [1] .Text;
objdc.parameterid = Convert.ToInt32(gv.Rows [e.RowIndex] .Cells [2] .Text);
objdc.headerID = Convert.ToInt32(gv.Rows [e.RowIndex] .Cells [1] .Text);
//objdc.paramsubname = gv.Rows [e.RowIndex] .Cells [3] .Text;
//objdc.headname =((Label)HeaderGv.Rows [e.RowIndex] .Cells [1] .FindControl("GroupLbl")).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 =会话["RoleName"].ToString();
int结果= objbl.updatechecklist(ref objdc);
如果(结果== 1)
{
文字li = new Literal();
FillmainGrid();
li.Text =< script> alert(``数据已成功更新'');</script>";
Page.Controls.Add(li);
}

}
catch(ex ex例外)
{
log.Error(ex.Message,ex);
}
}
受保护的void ParameterGv_RowEditing(对象发送者,GridViewEditEventArgs e)
{//子网格rowedit事件
FillmainGrid();
GridView gvtemp =(GridView)发送器;
gvtemp.EditIndex = e.NewEditIndex;


}
受保护的void ParameterGv_RowCommand(对象发送者,GridViewCommandEventArgs e)
{//子网格行命令
GridViewRow row =(GridViewRow)((Control)e.CommandSource).Parent.Parent;
GridView gv =(GridView)(e.CommandSource);
//string s = gv.DataKeys [row.RowIndex] [0] .ToString();
int i = Convert.ToInt32(e.CommandArgument);
GridViewRow子行= gv.Rows [i];
如果(e.CommandName =="Edit")
{

}
}
受保护的void ADDBtn_Click(对象发送者,EventArgs e)
{
试试
{
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 =会话["RoleName"].ToString();
objdc.modifiedby =会话["RoleName"].ToString();
objbl.insertchecklist(ref objdc);
}
j = j +1;
}
如果(j == HeaderGv.Rows.Count)
{
文字li = new Literal();
FillmainGrid();
HeaderGv.ShowFooter = false;
objbl.CloseAuditChecklist(ref objdc);
li.Text =< script> alert(``成功保存数据");</script>";
Page.Controls.Add(li);
}
}
catch(ex ex例外)
{
//文字li = new Literal();
//li.Text =< script> alert(""+ ex.Message +"'');</script>;
//Page.Controls.Add(li);
log.Error(ex.Message,ex);
}
}
受保护的void FreezeBtn_Click(对象发送者,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);
}
其他
{
Literal li = new Literal();
li.Text = "<script>alert(''Please close this form before freezing it'');</script>";
Page.Controls.Add(li);
}
}

}



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
//Creating an object for datacontainer class
DCCheckList objdc = new DCCheckList();
//creating an object for business layer class
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"];
//This method binds data to the gridview
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)
{//grid row data bound
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[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;
//if (ViewState["STATUS"] == "freezed")
//{
// e.Row.Cells[7].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;
//code for drop downs binds in child grid
((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;

//if (ViewState["STATUS"].ToString() == "freezed")
//{
// e.Row.Cells[7].Visible = false;
//}

}
}
protected void ParameterGv_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{// child grid row cancel event
e.Cancel = true;
HeaderGv.EditIndex = -1;
FillmainGrid();

}
protected void ParameterGv_RowUpdating(object sender, GridViewUpdateEventArgs e)
{//child grid row updating
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.headname = HeaderGv.Rows[e.RowIndex].Cells[1].Text;
objdc.parameterid = Convert.ToInt32(gv.Rows[e.RowIndex].Cells[2].Text);
objdc.headerID = Convert.ToInt32(gv.Rows[e.RowIndex].Cells[1].Text);
//objdc.paramsubname = gv.Rows[e.RowIndex].Cells[3].Text;
//objdc.headname = ((Label)HeaderGv.Rows[e.RowIndex].Cells[1].FindControl("GroupLbl")).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)
{//child grid rowedit event
FillmainGrid();
GridView gvtemp = (GridView)sender;
gvtemp.EditIndex = e.NewEditIndex;


}
protected void ParameterGv_RowCommand(object sender, GridViewCommandEventArgs e)
{//Child Grid rowcommand
GridViewRow row = (GridViewRow)((Control)e.CommandSource).Parent.Parent;
GridView gv = (GridView)(e.CommandSource);
//string s = gv.DataKeys[row.RowIndex][0].ToString();
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)
{
//Literal li = new Literal();
//li.Text = "<script>alert(''"+ex.Message+"'');</script>";
//Page.Controls.Add(li);
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);
}
}

}

推荐答案

First bind the grid and then assign edit index,
First bind the grid and then assign edit index,
protected void ParameterGv_RowEditing(object sender, GridViewEditEventArgs e)
{
  FillmainGrid();

  GridView gvtemp = (GridView)sender;
  gvtemp.EditIndex = e.NewEditIndex;
  
}


这篇关于更新行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆