这是我的第一个问题,所以如果你不理解它,那么我会更具体。
这是我的aspx代码
<asp:GridView ID="GridView1" runat="server" Style="margin-right: 0px" CellPadding="4" ForeColor="#333333" GridLines="None" ShowFooter="True" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="Nummer" HeaderText="Nummer" />
<asp:TemplateField HeaderText="Omschrijving" ControlStyle-Width="300px">
<FooterTemplate>
<asp:TextBox ID="txt_omschrijvingbank" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Grootboekrekening">
<FooterTemplate>
<asp:DropDownList ID="dr_grootboek" runat="server" DataSourceID="SqlDataSource2" DataTextField="grootboekrekening" DataValueField="grootboekrekeningnummer"></asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Btw">
<FooterTemplate>
<asp:DropDownList ID="drp_btw" runat="server">
<asp:ListItem>Selecteer btw</asp:ListItem>
<asp:ListItem>21%</asp:ListItem>
<asp:ListItem>6%</asp:ListItem>
<asp:ListItem>0%</asp:ListItem>
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Debet">
<FooterTemplate>
<asp:TextBox ID="txt_debet" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Credet">
<FooterTemplate>
<asp:TextBox ID="txt_credit" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="">
<FooterTemplate>
<asp:Button ID="btn_voegtoe" OnClick="Button3_Click" runat="server" Text="Voeg toe" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
这是我的代码
DataTable dt1 = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
gridVIEWData();
begin();
GridView1.DataSource = dt1;
GridView1.DataBind();
}
}
private void gridVIEWData()
{
dt1.Columns.Add(new DataColumn("Nummer", typeof(string)));
dt1.Columns.Add(new DataColumn("Omschrijving", typeof(string)));
dt1.Columns.Add(new DataColumn("Grootboekrekening", typeof(string)));
dt1.Columns.Add(new DataColumn("Btw", typeof(string)));
dt1.Columns.Add(new DataColumn("Debet", typeof(string)));
dt1.Columns.Add(new DataColumn("Credit", typeof(string)));
Session["dtInSession"] = dt1; //Saving Datatable To Session
}
protected void Button3_Click(object sender, EventArgs e)
{
if (Session["dtInSession"] != null)
dt1 = (DataTable)Session["dtInSession"]; //Getting datatable from session
TextBox Omschrijving = (TextBox)GridView1.FooterRow.FindControl("txt_omschrijvingbank");
DropDownList Grootboekrekening = (DropDownList)GridView1.FooterRow.FindControl("drp_grootboek");
DropDownList Btw = (DropDownList)GridView1.FooterRow.FindControl("drp_btw");
TextBox Debet = (TextBox)GridView1.FooterRow.FindControl("txt_debet");
TextBox Credit = (TextBox)GridView1.FooterRow.FindControl("txt_credit");
Response.Write(Credit.Text);
DataRow dr = dt1.NewRow();
dr["Nummer"] = 1;
dr["Omschrijving"] = Omschrijving.Text;
dr["Grootboekrekening"] = Grootboekrekening.SelectedItem;
dr["Btw"] = Btw.SelectedItem;
dr["Debet"] = Debet.Text;
dr["Credit"] = Credit.Text;
dt1.Rows.Add(dr);
Session["dtInSession"] = dt1; //Saving Datatable To Session
GridView1.DataSource = dt1;
GridView1.DataBind();
}
private void begin()
{
if (Session["dtInSession"] != null)
dt1 = (DataTable)Session["dtInSession"]; //Getting datatable from session
DataRow dr = dt1.NewRow();
dr["Nummer"] = 1;
dr["Omschrijving"] = string.Empty;
dr["Grootboekrekening"] = string.Empty;
dr["Btw"] = string.Empty;
dr["Debet"] = string.Empty;
dr["Credit"] = string.Empty;
dt1.Rows.Add(dr);
Session["dtInSession"] = dt1; //Saving Datatable To Session
GridView1.DataSource = dt1;
GridView1.DataBind();
}
在页脚中有几个texbox和一个按钮,如果按下按钮,它将创建一个新行,其中包含您在文本框中写入的数据。但这是问题:它正在创造一个新的行!!但是这行中没有数据。
我希望你们中的一些人可以帮助我。如果您需要更多细节,请询问
大安。
答案 0 :(得分:0)
如果您能够成功更新数据库中的数据,唯一的问题是它在更新后没有显示数据,那么您只需要重新加载页面。 尝试: 的Response.Redirect(Request.RawUrl);