var Proresult = (from s1 in ctx.FRRLists
select s1
).ToList(); ;
this.GridView1.DataKeyNames = new string[] { "FederalReimbursementRateSID" };
DataTable dt = Proresult.CopyToDataTable();
DataRow newRow = dt.NewRow();
int intDdlName = Convert.ToInt32(((DropDownList)GridView1.Rows[2].FindControl("DplName")).SelectedValue);
int intDdlprogram = Convert.ToInt32(((DropDownList)GridView1.Rows[2].FindControl("DplProgram")).SelectedValue);
DateTime DateStartDate = Convert.ToDateTime(((TextBox)GridView1.Rows[2].FindControl("TBStartDate")).Text);
DateTime DateEndDate = Convert.ToDateTime(((TextBox)GridView1.Rows[2].FindControl("TBEndDate")).Text);
decimal decfree = Convert.ToDecimal(((TextBox)GridView1.Rows[2].FindControl("TBFree")).Text);
decimal decReduced = Convert.ToDecimal(((TextBox)GridView1.Rows[2].FindControl("TBReducedRate")).Text);
decimal decPaid = Convert.ToDecimal(((TextBox)GridView1.Rows[2].FindControl("TBPaidRate")).Text);
newRow["StateTypeSID"] = intDdlName;
newRow["ProgramSID"] = intDdlprogram;
newRow["Needy"] = true;
newRow["StartDate"] = DateStartDate;
newRow["EndDate"] = DateEndDate;
newRow["PaidRate"] = decPaid;
newRow["ReducedRate"] = decReduced;
newRow["Free"] = decfree;
newRow["LastChangedUser"] =0;
newRow["LastChangedDate"] = DateTime.Now;
newRow["StateTypeSID"] = intDdlName;
newRow["StateTypeSID"] = intDdlName; dt.Rows.InsertAt(newRow, 0);
GridView1.DataSource = dt;
GridView1.DataBind();
select s1
).ToList(); ;
this.GridView1.DataKeyNames = new string[] { "FederalReimbursementRateSID" };
DataTable dt = Proresult.CopyToDataTable();
DataRow newRow = dt.NewRow();
int intDdlName = Convert.ToInt32(((DropDownList)GridView1.Rows[2].FindControl("DplName")).SelectedValue);
int intDdlprogram = Convert.ToInt32(((DropDownList)GridView1.Rows[2].FindControl("DplProgram")).SelectedValue);
DateTime DateStartDate = Convert.ToDateTime(((TextBox)GridView1.Rows[2].FindControl("TBStartDate")).Text);
DateTime DateEndDate = Convert.ToDateTime(((TextBox)GridView1.Rows[2].FindControl("TBEndDate")).Text);
decimal decfree = Convert.ToDecimal(((TextBox)GridView1.Rows[2].FindControl("TBFree")).Text);
decimal decReduced = Convert.ToDecimal(((TextBox)GridView1.Rows[2].FindControl("TBReducedRate")).Text);
decimal decPaid = Convert.ToDecimal(((TextBox)GridView1.Rows[2].FindControl("TBPaidRate")).Text);
newRow["StateTypeSID"] = intDdlName;
newRow["ProgramSID"] = intDdlprogram;
newRow["Needy"] = true;
newRow["StartDate"] = DateStartDate;
newRow["EndDate"] = DateEndDate;
newRow["PaidRate"] = decPaid;
newRow["ReducedRate"] = decReduced;
newRow["Free"] = decfree;
newRow["LastChangedUser"] =0;
newRow["LastChangedDate"] = DateTime.Now;
newRow["StateTypeSID"] = intDdlName;
newRow["StateTypeSID"] = intDdlName; dt.Rows.InsertAt(newRow, 0);
GridView1.DataSource = dt;
GridView1.DataBind();
ds.Tables[0].Rows.InsertAt(dr, 0);
GridView1.DataSource = ds;
GridView1.DataBind();这样就可以添加一个空白行,然后你可以点击编辑对该行进行添加数据
AllowPaging="True" PageSize="12" OnRowCancelingEdit="GridView1_RowCancelingEdit"
OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" OnRowDeleting="GridView1_RowDeleting"
OnPageIndexChanging="GridView1_PageIndexChanging"
OnRowDataBound="GridView1_RowDataBound" GridLines="None" AllowSorting="True"
onsorting="GridView1_Sorting" >
<Columns>
<%-- <asp:TemplateField HeaderText="StartDate">
<ItemTemplate>
<%#Convert.ToDateTime(DataBinder.Eval(Container.DataItem, "StartDate").ToString()).ToLongDateString()%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="EndDate">
<ItemTemplate>
<%#Convert.ToDateTime(DataBinder.Eval(Container.DataItem, "EndDate").ToString()).ToLongDateString()%>
</ItemTemplate>
</asp:TemplateField>--%>
<asp:BoundField DataField="FederalReimbursementRateSID"
HeaderText="FederalReimbursementRateSID" Visible="False" />
<%-- <asp:BoundField DataField="Name" HeaderText="Name" ReadOnly="false"/>
<asp:BoundField DataField="Program" HeaderText="Program" ReadOnly="false" />
<asp:BoundField DataField="Criteria" HeaderText="Criteria" ReadOnly="false" />
<asp:BoundField DataField="StartDate" HeaderText="StartDate" ReadOnly="false"
DataFormatString="{0:MM/dd/yyyy}" />
<asp:BoundField DataField="EndDate" HeaderText="EndDate" ReadOnly="false"
DataFormatString="{0:MM/dd/yyyy}" />
<asp:BoundField DataField="Free" HeaderText="Free" ReadOnly="false" />
<asp:BoundField DataField="ReducedRate" HeaderText="ReducedRate" ReadOnly="false" />
<asp:BoundField DataField="PaidRate" HeaderText="PaidRate" ReadOnly="false"/>
--%>
<asp:TemplateField HeaderText="Name" SortExpression="Name">
<ItemTemplate>
<%# Eval("Name")%>
</ItemTemplate>
<EditItemTemplate>
<asp:HiddenField ID="HdplName" runat="server" Value='<%# Eval("StateTypeSID") %>' />
<asp:DropDownList ID="DplName" runat="server" Width="140px" />
</EditItemTemplate>
<ItemStyle Width="150px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Program" SortExpression="Program">
<ItemTemplate>
<%# Eval("Program")%>
</ItemTemplate>
<EditItemTemplate>
<asp:HiddenField ID="HdplProgram" runat="server" Value='<%# Eval("ProgramSID") %>' />
<asp:DropDownList ID="DplProgram" runat="server" Width="140px" />
</EditItemTemplate>
<ItemStyle Width="150px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Criteria" SortExpression="Criteria">
<ItemTemplate>
<%# Eval("Criteria")%>
</ItemTemplate>
<EditItemTemplate>
<%--<asp:HiddenField ID="HdplCriteria" runat="server" Value='<%# Eval("StateTypeSID") %>' />--%>
<asp:DropDownList ID="DplCriteria" runat="server" Width="140px" />
</EditItemTemplate>
<ItemStyle Width="150px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="StartDate" SortExpression="StartDate">
<ItemTemplate>
<%# Eval("StartDate", "{0:yyyy-MM-dd}").ToString()%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TBStartDate" Text='<%# Eval("StartDate", "{0:yyyy-MM-dd}").ToString()%>' runat="server" Width="140px" />
</EditItemTemplate>
<ItemStyle Width="150px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="EndDate" SortExpression="EndDate">
<ItemTemplate>
<%# Eval("EndDate", "{0:yyyy-MM-dd}").ToString()%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TBEndDate" Text='<%# Eval("EndDate", "{0:yyyy-MM-dd}").ToString()%>' runat="server" Width="140px" />
</EditItemTemplate>
<ItemStyle Width="150px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Free" SortExpression="Free">
<ItemTemplate>
<%# Eval("Free")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TBFree" Text='<%# Eval("Free") %>' runat="server" Width="140px" />
</EditItemTemplate>
<ItemStyle Width="150px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="ReducedRate" SortExpression="ReducedRate">
<ItemTemplate>
<%# Eval("ReducedRate")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TBReducedRate" Text='<%# Eval("ReducedRate") %>' runat="server" Width="140px" />
</EditItemTemplate>
<ItemStyle Width="150px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="PaidRate" SortExpression="PaidRate">
<ItemTemplate>
<%# Eval("PaidRate")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TBPaidRate" Text='<%# Eval("PaidRate") %>' runat="server" Width="140px" />
</EditItemTemplate>
<ItemStyle Width="150px" />
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" HeaderText="Edit" />
<asp:CommandField HeaderText="Delete" ShowDeleteButton="True"
ButtonType="Image" DeleteImageUrl="~/images/X_delete.gif" />
</Columns>
</asp:GridView>
{
var Proresult = (from s1 in ctx.FRRLists
select s1
).ToList(); ;
this.GridView1.DataKeyNames = new string[] { "FederalReimbursementRateSID" };
DataTable dt = Proresult.CopyToDataTable();
DataRow newRow = dt.NewRow();
//int intDdlName = Convert.ToInt32(((DropDownList)GridView1.Rows[2].FindControl("DplName")).SelectedValue);
//int intDdlprogram = Convert.ToInt32(((DropDownList)GridView1.Rows[2].FindControl("DplProgram")).SelectedValue);
//DateTime DateStartDate = Convert.ToDateTime(((TextBox)GridView1.Rows[2].FindControl("TBStartDate")).Text);
//DateTime DateEndDate = Convert.ToDateTime(((TextBox)GridView1.Rows[2].FindControl("TBEndDate")).Text);
//decimal decfree = Convert.ToDecimal(((TextBox)GridView1.Rows[2].FindControl("TBFree")).Text);
//decimal decReduced = Convert.ToDecimal(((TextBox)GridView1.Rows[2].FindControl("TBReducedRate")).Text);
//decimal decPaid = Convert.ToDecimal(((TextBox)GridView1.Rows[2].FindControl("TBPaidRate")).Text);
//DataRow dr = ds.Tables[0].NewRow();
//ds.Tables[0].Rows.InsertAt(dr, 0);
//GridView1.DataSource = ds;
//GridView1.DataBind();
//int intDdlName = 1;
//int intDdlprogram = 2;
//DateTime DateStartDate = DateTime.Now;
//DateTime DateEndDate = DateTime.Now;
//decimal decfree = Convert.ToDecimal("0.23");
//decimal decReduced = Convert.ToDecimal("0.23");
//decimal decPaid = Convert.ToDecimal("0.23");
//newRow["StateTypeSID"] = intDdlName;
//newRow["ProgramSID"] = intDdlprogram;
//newRow["Needy"] = true;
//newRow["StartDate"] = DateStartDate;
//newRow["EndDate"] = DateEndDate;
//newRow["PaidRate"] = decPaid;
//newRow["ReducedRate"] = decReduced;
//newRow["Free"] = decfree;
//newRow["LastChangedUser"] =0;
//newRow["LastChangedDate"] = DateTime.Now;
dt.Rows.InsertAt(newRow, 0);
GridView1.DataSource = dt;
GridView1.DataBind();
//BindData();
}