tags:

views:

217

answers:

1

Hi,
I am working on a application where i am using rowupdating event of the gridview. I am using templatefield in my columns so i am not able to get the new values from the textboxws that i am having in the gridview. How can i get the new values from the textboxes. Following is my code in 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");
} 

i want to get the new values form these textboxes but it is always giving me old values. and yes, e.Newvalues is not giving me anything. It is always empty. This is small extract from my gridview design:

<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>

Can anyone please tell me how to get the new values from these textboxes?

A: 

Hi, you need to bind grid as If Not IsPostBack Then ' bind end if

Subaiee