【问题标题】:rowupdating not giving new values行更新不提供新值
【发布时间】:2012-02-17 14:56:41
【问题描述】:

我正在开发一个使用 gridview 的 rowupdating 事件的应用程序。我在我的列中使用模板字段,所以我无法从我在 gridview 中拥有的 textboxws 中获取新值。如何从文本框中获取新值。以下是我在 rowupdating 中的代码:

protected void gviewTemplate_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    gviewTemplate.EditIndex = -1;
    string rowNum = ViewState["ID"].ToString();
    Label lbl2 = (Label)gviewTemplate.Rows[e.RowIndex].FindControl("lblTemplateName");
    Label lbl1 = (Label)gviewTemplate.Rows[e.RowIndex].FindControl("lblUploaded");

    TextBox txtTempName = (TextBox)gviewTemplate.Rows[e.RowIndex].FindControl("txtTemplateName");
    TextBox txtHeading = (TextBox)gviewTemplate.Rows[e.RowIndex].FindControl("txtHeading");
    TextBox txtCoupon = (TextBox)gviewTemplate.Rows[e.RowIndex].FindControl("txtCouponText");
    TextBox txtBrand = (TextBox)gviewTemplate.Rows[e.RowIndex].FindControl("txtBrandName");
    TextBox txtSearchText = (TextBox)gviewTemplate.Rows[e.RowIndex].FindControl("txtSearch");
    TextBox txtDiscount = (TextBox)gviewTemplate.Rows[e.RowIndex].FindControl("txtDiscount");
    TextBox txtStartDt = (TextBox)gviewTemplate.Rows[e.RowIndex].FindControl("txtStartDt");
} 

我想从这些文本框中获取新值,但它总是给我旧值。是的,e.Newvalues 没有给我任何东西。它总是空的。这是我的 gridview 设计的一小部分摘录:

<asp:GridView runat="server" AutoGenerateColumns="False"  
                        ID="gviewTemplate" onrowdatabound="gviewTemplate_RowDataBound" DataKeyNames="F1"
                        onrowcommand="gviewTemplate_RowCommand" 
                        onrowediting="gviewTemplate_RowEditing" 
                        onrowcancelingedit="gviewTemplate_RowCancelingEdit" 
                        onrowupdating="gviewTemplate_RowUpdating" 
                        onrowdeleting="gviewTemplate_RowDeleting" 
                        onrowupdated="gviewTemplate_RowUpdated">
                        <Columns>
                            <asp:TemplateField HeaderText="Uploaded Image">
                            <EditItemTemplate>
                                <asp:LinkButton Text="Reload" runat="server" OnClick="lbtnReloadImage_Click" CommandName="reload" ID="lbtnReloadImage"></asp:LinkButton>
                            </EditItemTemplate>
                                <ItemTemplate>
                                    <table id="Table2" runat="server" width="100%" cellpadding="0" cellspacing="0" border="0">
                                        <tr>
                                            <td>
                                                <asp:Label Runat="server" Text='<%# Eval("Uploaded") %>' ID="lblUploaded"></asp:Label>
                                            </td>
                                        </tr>
                                    </table>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Template Name">
                                <ItemStyle VerticalAlign="Top" HorizontalAlign="Center" />
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtTemplateName" Width="60" Runat="server" Text='<%# Eval("F1") %>'></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" Runat="server" 
                                    ErrorMessage="You must provide a Product Name." ControlToValidate="txtTemplateName">*</asp:RequiredFieldValidator>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <table id="Table3" runat="server" width="100%" cellpadding="0" cellspacing="0" border="0">
                                        <tr>
                                            <td>
                                                <asp:Label ID="lblTemplateName" runat="server" Text='<%# Eval("F1") %>'></asp:Label>
                                            </td>
                                        </tr>
                                    </table>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Heading">
                                <ItemStyle VerticalAlign="Top" HorizontalAlign="Center" />
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtHeading" Runat="server" Width="60" Text='<%# Eval("F2") %>'></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" Runat="server" 
                                    ErrorMessage="You must provide a Product Name." ControlToValidate="txtHeading">*</asp:RequiredFieldValidator>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <table id="Table4" runat="server" width="100%" cellpadding="0" cellspacing="0" border="0">
                                        <tr>
                                            <td>
                                                <asp:Label ID="lblHeading" runat="server" Text='<%# Eval("F2") %>'></asp:Label>
                                            </td>
                                        </tr>
                                    </table>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Coupon Text">
                                <ItemStyle VerticalAlign="Top" HorizontalAlign="Center" />
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtCouponText" Runat="server" Width="80" Text='<%# Bind("F3") %>'></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" Runat="server" 
                                    ErrorMessage="You must provide a Product Name." ControlToValidate="txtCouponText">*</asp:RequiredFieldValidator>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <table id="Table5" runat="server" width="100%" cellpadding="0" cellspacing="0" border="0">
                                        <tr>
                                            <td>
                                                <asp:Label Runat="server" Text='<%# Bind("F3") %>' ID="lblCouponText"></asp:Label>
                                            </td>
                                        </tr>
                                    </table>
                                </ItemTemplate>
                            </asp:TemplateField>

谁能告诉我如何从这些文本框中获取新值?

【问题讨论】:

  • 我该怎么做,我不知道如何接受答案

标签: gridview


【解决方案1】:

不要重新绑定GridView,如果页面不是回发就绑定它

【讨论】:

    【解决方案2】:

    您需要将网格绑定为 If Not IsPostBack Then '绑定 结束如果

    【讨论】:

      猜你喜欢
      • 2016-05-14
      • 2021-06-17
      • 2020-08-24
      • 2020-06-23
      • 1970-01-01
      • 1970-01-01
      • 2017-03-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多