gridview点击增加按钮,增加一行,输入内容,没有按保存按钮,再点击增加按钮,增加一行时却清空了上一行的内容,怎么才能 不清空?
前台:
<asp:GridView ID="gvContentAssign1" runat="server" AutoGenerateColumns="false" AllowPaging="false" EmptyDataText="null" Width="100%" OnRowDataBound="gvRowDatabound" OnRowEditing="gvRowEditing"> <Columns> <asp:TemplateField HeaderText="<%$ resources:Section %>"> <ItemTemplate> <asp:Label ID="lbSection1" runat="server" style="font-size:14pt" Text="<%# Bind('SectionDesc2') %>"></asp:Label> </ItemTemplate> <ItemStyle Width="4%" /> <HeaderStyle Width="4%" /> </asp:TemplateField> </Columns> </asp:GridView>
后台
addCommand:
protected void gvBtnAdd1_Command(object sender, CommandEventArgs e) { SectionOverviewConfig sConf = SectionOverviewConfig.GetCurrentConfig(); if (string.IsNullOrWhiteSpace(sConf.curSearchCritiraCa.selectedSection)) { Common.Common.ShowMessage(Page, (String)(GetLocalResourceObject("PleaseSelectSection"))); return; } else { gvdt1.Clear(); rownow = 0; foreach (GridViewRow dr in gvContentAssign1.Rows) { DataRow newRow = gvdt1.NewRow(); newRow["AssignmentDate"] = ((Label)dr.FindControl("LabelTime1")).Text; newRow["SmallScale"] = ((Label)dr.FindControl("lbSmallScale")).Text; newRow["InterviewContent"] = ((Label)dr.FindControl("lbAssigment1")).Text; newRow["Address"] = ((Label)dr.FindControl("lbAddress1")).Text; newRow["ReporterName1"] = ((Label)dr.FindControl("lbReporter1")).Text; newRow["ReporterName2"] = ((Label)dr.FindControl("lbReporterB1")).Text; newRow["PhotographerName1"] = ((Label)dr.FindControl("lbPhotographer1")).Text; newRow["PhotographerName2"] = ((Label)dr.FindControl("lbPhotographerB1")).Text; newRow["PhotoVideo"] = ((Label)dr.FindControl("lbPhotoVideo1")).Text; newRow["Remark"] = ((Label)dr.FindControl("lbRemark1")).Text; newRow["isExistingRow"] = ((Label)dr.FindControl("lbError")).Text; newRow["PubCode"] = ((Label)dr.FindControl("lbPublication1")).Text; newRow["SectionCode2"] = ((Label)dr.FindControl("lbSection1")).Text; gvdt1.Rows.Add(newRow); } DataRow oldRow = gvdt1.NewRow(); oldRow["isExistingRow"] = "F"; gvdt1.Rows.Add(oldRow); rownow++; rownum1 ++ ; gvContentAssign1.DataSource = gvdt1; gvContentAssign1.DataBind(); } }
databind
public override void DataBind() { rownum1 = 0; rownum2 = 0; DataTable dt1 = new DataTable(); //smallscale=0 dt1.Columns.Add(new DataColumn("CA_id", typeof(string))); dt1.Columns.Add(new DataColumn("PubCode", typeof(string))); dt1.Columns.Add(new DataColumn("SectionCode2", typeof(string))); dt1.Columns.Add(new DataColumn("AssignmentDate", typeof(string))); //datetime dt1.Columns.Add(new DataColumn("AssignmentDateHH", typeof(string))); //display hour dt1.Columns.Add(new DataColumn("AssignmentDateMM", typeof(string))); //display minute dt1.Columns.Add(new DataColumn("InterviewContent", typeof(string))); dt1.Columns.Add(new DataColumn("Address", typeof(string))); dt1.Columns.Add(new DataColumn("ReporterName1", typeof(string))); dt1.Columns.Add(new DataColumn("ReporterName2", typeof(string))); dt1.Columns.Add(new DataColumn("ReporterTelNumber1", typeof(string))); dt1.Columns.Add(new DataColumn("ReporterTelNumber2", typeof(string))); dt1.Columns.Add(new DataColumn("PhotographerName1", typeof(string))); dt1.Columns.Add(new DataColumn("PhotographerName2", typeof(string))); dt1.Columns.Add(new DataColumn("PhotographerTelNumber1", typeof(string))); dt1.Columns.Add(new DataColumn("PhotographerTelNumber2", typeof(string))); dt1.Columns.Add(new DataColumn("PhotoVideo", typeof(string))); dt1.Columns.Add(new DataColumn("Remark", typeof(string))); dt1.Columns.Add(new DataColumn("isExistingRow", typeof(string))); dt1.Columns.Add(new DataColumn("SmallScale",typeof(string))); dt1.Columns.Add(new DataColumn("SectionDesc2", typeof(string))); SectionOverviewConfig sConf = SectionOverviewConfig.GetCurrentConfig(); ContentAssignmentDataSet dsContentAssignment = ContentAssignmentManager.GetReporterList(sConf.ddlPublicationSelectedValue,null ); lbGuide.Visible = true; foreach (ContentAssignmentDataSet.ContentAssignmentRow r in sConf.contentAssignmentList.ContentAssignment ) { DataRow dr = dt1.NewRow(); dr["AssignmentDate"] = ((DateTime)r["AssignmentDate"]).ToString("HH:mm"); dr["AssignmentDateHH"] = (((DateTime)r["AssignmentDate"]).ToString("HH:mm")).Substring(0, 2); dr["AssignmentDateMM"] = (((DateTime)r["AssignmentDate"]).ToString("HH:mm")).Substring(3, 2); dr["InterviewContent"] = r["InterviewContent"].ToString(); dr["Address"] = r["Address"].ToString(); foreach (ContentAssignmentDataSet.ContentAssignmentGetPeopleRow d in dsContentAssignment.ContentAssignmentGetPeople) { if ( r["ReporterName1"].Equals(d.UserID.ToString()) ) { dr["ReporterTelNumber1"] = d["TelNumber"].ToString(); dr["ReporterName1"] = d["UserName"].ToString(); } if (r["ReporterName2"].Equals( d.UserID.ToString())) { dr["ReporterTelNumber2"] = d["TelNumber"].ToString(); dr["ReporterName2"] = d["UserName"].ToString(); } if (r["PhotographerName1"].Equals(d.UserID.ToString())) { dr["PhotographerTelNumber1"] = d["TelNumber"].ToString(); dr["PhotographerName1"] = d["UserName"].ToString(); } if (r["PhotographerName2"].Equals(d.UserID.ToString())) { dr["PhotographerTelNumber2"] = d["TelNumber"].ToString(); dr["PhotographerName2"] = d["UserName"].ToString(); } } if (r["PhotoVideo"].ToString() == "1") { dr["PhotoVideo"] = "P"; } else if (r["PhotoVideo"].ToString() == "2") { dr["PhotoVideo"] = "V"; } else if (r["PhotoVideo"].ToString() == "3") { dr["PhotoVideo"] = "P+V"; } else if (r["PhotoVideo"].ToString() == "0") { dr["PhotoVideo"] = " "; } if (r["SmallScale"].ToString() == "1") { dr["SmallScale"] = "勿駁"; } else if(r["SmallScale"].ToString() == "0") { dr["SmallScale"] = " "; } dr["PubCode"] = r["PubCode"].ToString(); dr["SectionCode2"] = r["SectionCode2"].ToString(); dr["Remark"] = r["Remark"].ToString(); dr["CA_id"] = r["CA_id"].ToString(); dr["isExistingRow"] = "T"; //dr["SmallScale"] = r["SmallScale"].ToString(); dr["SectionDesc2"] = r["SectionDesc2"].ToString(); dt1.Rows.Add(dr); rownow++; rownum1 = dt1.Rows.Count; } if (dt1.Rows.Count <= 0) { DataRow drx1 = dt1.NewRow(); drx1["isExistingRow"] = "F"; dt1.Rows.Add(drx1); gvdt1 = dt1; gvContentAssign1.DataSource = dt1; gvContentAssign1.DataBind(); } else { gvdt1 = dt1; gvContentAssign1.DataSource = dt1; gvContentAssign1.DataBind(); } dtDeleted = new DataTable(); dtDeleted.Columns.Add("AssignmentDate", typeof(string)); }
别浪费时间了,这些操作应该用Jquery来做
jq总是拿不到控件的id,请问能教教我吗?
@rivahuang: 这个你看下Jq教程、视频就行了,拿控件ID是最简单的操作了