How reference text box in GridView while in edit mode?

Discussion in 'ASP .Net' started by VB Programmer, Aug 15, 2006.

  1. I have a gridview control with several data fields. When the user clicks
    'edit' for the row I want the user to be able to edit a particular text
    field. Under that 'edit' textbox is a button. When they click on the
    button it fills in the textbox with some standard text.

    Question: In the code for the button how do I reference the textbox
    'FreeTextBox1' (for the current edit row)?

    Here's the gridview layout...

    <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
    AllowSorting="True"
    AutoGenerateColumns="False" CellPadding="4" DataKeyNames="ProductId"
    DataSourceID="sdsProducts"
    ForeColor="#333333" GridLines="None">
    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"
    />
    <Columns>
    <asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
    />
    <asp:TemplateField HeaderText="Category"
    SortExpression="CategoryId">
    <EditItemTemplate>
    <asp:DropDownList ID="ddlCategory" runat="server"
    DataSourceID="sdsCategory"
    DataTextField="CategoryName"
    DataValueField="CategoryId" SelectedValue='<%# Bind("CategoryId") %>' >
    </asp:DropDownList>
    </EditItemTemplate>
    <ItemTemplate>
    &nbsp;<asp:Label ID="Label1" runat="server" Text='<%#
    Bind("CategoryName") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataField="ProductCode" HeaderText="Product
    Code" SortExpression="ProductCode" />
    <asp:BoundField DataField="ProductTitle" HeaderText="Title"
    SortExpression="ProductTitle" >
    <ItemStyle Width="200px" />
    </asp:BoundField>
    <asp:TemplateField HeaderText="Description"
    SortExpression="ProductDescription">
    <EditItemTemplate>
    <FTB:FreeTextBox ID="FreeTextBox1" runat="server"
    AllowHtmlMode="False" AssemblyResourceHandlerPath=""
    AutoConfigure=""
    AutoGenerateToolbarsFromString="True" AutoHideToolbar="True"
    AutoParseStyles="True" BackColor="158, 190, 245"
    BaseUrl="" BreakMode="Paragraph"
    ButtonDownImage="False" ButtonFileExtention="gif"
    ButtonFolder="Images" ButtonHeight="20"
    ButtonImagesLocation="InternalResource"
    ButtonOverImage="False" ButtonPath=""
    ButtonSet="Office2003" ButtonWidth="21"
    ClientSideTextChanged="" ConvertHtmlSymbolsToHtmlCodes="False"
    DesignModeBodyTagCssClass="" DesignModeCss=""
    DisableIEBackButton="False" DownLevelCols="50"
    DownLevelMessage="" DownLevelMode="TextArea"
    DownLevelRows="10" EditorBorderColorDark="128, 128, 128"
    EditorBorderColorLight="128, 128, 128"
    EnableHtmlMode="True" EnableSsl="False"
    EnableToolbars="True" Focus="False"
    FormatHtmlTagsToXhtml="True" GutterBackColor="129, 169, 226"
    GutterBorderColorDark="128, 128, 128"
    GutterBorderColorLight="255, 255, 255"
    Height="150px" HelperFilesParameters=""
    HelperFilesPath="" HtmlModeCss="" HtmlModeDefaultsToMonoSpaceFont="True"
    ImageGalleryPath="~/images/"
    ImageGalleryUrl="ftb.imagegallery.aspx?rif={0}&cif={0}"
    InstallationErrorMessage="InlineMessage"
    JavaScriptLocation="InternalResource"
    Language="en-US" PasteMode="Default"
    ReadOnly="False" RemoveScriptNameFromBookmarks="True"
    RemoveServerNameFromUrls="True" RenderMode="NotSet"
    ScriptMode="External" ShowTagPath="False"
    SslUrl="/." StartMode="DesignMode"
    StripAllScripting="False" SupportFolder="/aspnet_client/FreeTextBox/"
    TabIndex="-1" TabMode="InsertSpaces" Text='<%#
    Bind("ProductDescription") %>'
    TextDirection="LeftToRight"
    ToolbarBackColor="Transparent" ToolbarBackgroundImage="True"
    ToolbarImagesLocation="InternalResource"
    ToolbarLayout="ParagraphMenu,FontFacesMenu,FontSizesMenu,FontForeColorsMenu|Bold,Italic,Underline,Strikethrough;Superscript,Subscript,RemoveFormat|JustifyLeft,JustifyRight,JustifyCenter,JustifyFull;BulletedList,NumberedList,Indent,Outdent;CreateLink,Unlink,InsertImage,InsertRule|Cut,Copy,Paste;Undo,Redo,Print"
    ToolbarStyleConfiguration="NotSet"
    UpdateToolbar="True" UseToolbarBackGroundImage="True"
    Width="350px">
    </FTB:FreeTextBox>
    <asp:Button ID="cmdEditFreeShip" runat="server"
    OnClick="cmdEditFreeShip_Click" Text="Add Free Shipping" />
    </EditItemTemplate>
    <ItemStyle Width="200px" />
    <ItemTemplate>
    <asp:Label ID="Label2" runat="server" Text='<%#
    Bind("ProductDescription") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataField="ProductPriceOriginal" HeaderText="Was
    Price" SortExpression="ProductPriceOriginal" DataFormatString="{0:c}" />
    <asp:BoundField DataField="ProductPrice" HeaderText="Price"
    SortExpression="ProductPrice" DataFormatString="{0:c}" />
    <asp:BoundField DataField="ProductPic" HeaderText="Image"
    SortExpression="ProductPic" />
    <asp:BoundField DataField="ProductId" HeaderText="ProductId"
    ReadOnly="True" SortExpression="ProductId"
    Visible="False" />
    </Columns>
    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    <EditRowStyle BackColor="#999999" />
    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True"
    ForeColor="#333333" />
    <PagerStyle BackColor="#284775" ForeColor="White"
    HorizontalAlign="Center" />
    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"
    />
    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    </asp:GridView>
    VB Programmer, Aug 15, 2006
    #1
    1. Advertising

  2. Have you tried?
    Dim tb As TextBox = CType(GridView1.FindControl("'FreeTextBox1'"), TextBox)
    Patrick



    "VB Programmer" <> wrote in message
    news:...
    >I have a gridview control with several data fields. When the user clicks
    >'edit' for the row I want the user to be able to edit a particular text
    >field. Under that 'edit' textbox is a button. When they click on the
    >button it fills in the textbox with some standard text.
    >
    > Question: In the code for the button how do I reference the textbox
    > 'FreeTextBox1' (for the current edit row)?
    >
    > Here's the gridview layout...
    >
    > <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
    > AllowSorting="True"
    > AutoGenerateColumns="False" CellPadding="4"
    > DataKeyNames="ProductId" DataSourceID="sdsProducts"
    > ForeColor="#333333" GridLines="None">
    > <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"
    > />
    > <Columns>
    > <asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
    > />
    > <asp:TemplateField HeaderText="Category"
    > SortExpression="CategoryId">
    > <EditItemTemplate>
    > <asp:DropDownList ID="ddlCategory" runat="server"
    > DataSourceID="sdsCategory"
    > DataTextField="CategoryName"
    > DataValueField="CategoryId" SelectedValue='<%# Bind("CategoryId") %>' >
    > </asp:DropDownList>
    > </EditItemTemplate>
    > <ItemTemplate>
    > &nbsp;<asp:Label ID="Label1" runat="server" Text='<%#
    > Bind("CategoryName") %>'></asp:Label>
    > </ItemTemplate>
    > </asp:TemplateField>
    > <asp:BoundField DataField="ProductCode" HeaderText="Product
    > Code" SortExpression="ProductCode" />
    > <asp:BoundField DataField="ProductTitle" HeaderText="Title"
    > SortExpression="ProductTitle" >
    > <ItemStyle Width="200px" />
    > </asp:BoundField>
    > <asp:TemplateField HeaderText="Description"
    > SortExpression="ProductDescription">
    > <EditItemTemplate>
    > <FTB:FreeTextBox ID="FreeTextBox1" runat="server"
    > AllowHtmlMode="False" AssemblyResourceHandlerPath=""
    > AutoConfigure=""
    > AutoGenerateToolbarsFromString="True" AutoHideToolbar="True"
    > AutoParseStyles="True" BackColor="158, 190, 245"
    > BaseUrl="" BreakMode="Paragraph"
    > ButtonDownImage="False" ButtonFileExtention="gif"
    > ButtonFolder="Images" ButtonHeight="20"
    > ButtonImagesLocation="InternalResource"
    > ButtonOverImage="False" ButtonPath=""
    > ButtonSet="Office2003" ButtonWidth="21"
    > ClientSideTextChanged="" ConvertHtmlSymbolsToHtmlCodes="False"
    > DesignModeBodyTagCssClass="" DesignModeCss=""
    > DisableIEBackButton="False" DownLevelCols="50"
    > DownLevelMessage="" DownLevelMode="TextArea"
    > DownLevelRows="10" EditorBorderColorDark="128, 128, 128"
    > EditorBorderColorLight="128, 128, 128"
    > EnableHtmlMode="True" EnableSsl="False"
    > EnableToolbars="True" Focus="False"
    > FormatHtmlTagsToXhtml="True" GutterBackColor="129, 169, 226"
    > GutterBorderColorDark="128, 128, 128"
    > GutterBorderColorLight="255, 255, 255"
    > Height="150px" HelperFilesParameters=""
    > HelperFilesPath="" HtmlModeCss="" HtmlModeDefaultsToMonoSpaceFont="True"
    > ImageGalleryPath="~/images/"
    > ImageGalleryUrl="ftb.imagegallery.aspx?rif={0}&cif={0}"
    > InstallationErrorMessage="InlineMessage"
    > JavaScriptLocation="InternalResource"
    > Language="en-US" PasteMode="Default"
    > ReadOnly="False" RemoveScriptNameFromBookmarks="True"
    > RemoveServerNameFromUrls="True" RenderMode="NotSet"
    > ScriptMode="External" ShowTagPath="False"
    > SslUrl="/." StartMode="DesignMode"
    > StripAllScripting="False" SupportFolder="/aspnet_client/FreeTextBox/"
    > TabIndex="-1" TabMode="InsertSpaces" Text='<%#
    > Bind("ProductDescription") %>'
    > TextDirection="LeftToRight"
    > ToolbarBackColor="Transparent" ToolbarBackgroundImage="True"
    > ToolbarImagesLocation="InternalResource"
    > ToolbarLayout="ParagraphMenu,FontFacesMenu,FontSizesMenu,FontForeColorsMenu|Bold,Italic,Underline,Strikethrough;Superscript,Subscript,RemoveFormat|JustifyLeft,JustifyRight,JustifyCenter,JustifyFull;BulletedList,NumberedList,Indent,Outdent;CreateLink,Unlink,InsertImage,InsertRule|Cut,Copy,Paste;Undo,Redo,Print"
    > ToolbarStyleConfiguration="NotSet"
    > UpdateToolbar="True" UseToolbarBackGroundImage="True"
    > Width="350px">
    > </FTB:FreeTextBox>
    > <asp:Button ID="cmdEditFreeShip" runat="server"
    > OnClick="cmdEditFreeShip_Click" Text="Add Free Shipping" />
    > </EditItemTemplate>
    > <ItemStyle Width="200px" />
    > <ItemTemplate>
    > <asp:Label ID="Label2" runat="server" Text='<%#
    > Bind("ProductDescription") %>'></asp:Label>
    > </ItemTemplate>
    > </asp:TemplateField>
    > <asp:BoundField DataField="ProductPriceOriginal"
    > HeaderText="Was Price" SortExpression="ProductPriceOriginal"
    > DataFormatString="{0:c}" />
    > <asp:BoundField DataField="ProductPrice" HeaderText="Price"
    > SortExpression="ProductPrice" DataFormatString="{0:c}" />
    > <asp:BoundField DataField="ProductPic" HeaderText="Image"
    > SortExpression="ProductPic" />
    > <asp:BoundField DataField="ProductId" HeaderText="ProductId"
    > ReadOnly="True" SortExpression="ProductId"
    > Visible="False" />
    > </Columns>
    > <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    > <EditRowStyle BackColor="#999999" />
    > <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True"
    > ForeColor="#333333" />
    > <PagerStyle BackColor="#284775" ForeColor="White"
    > HorizontalAlign="Center" />
    > <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"
    > />
    > <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    > </asp:GridView>
    >
    Patrick.O.Ige, Aug 16, 2006
    #2
    1. Advertising

  3. Thanks Patrick. I assume that this will work based on the "current row"?

    "Patrick.O.Ige" <> wrote in message
    news:...
    > Have you tried?
    > Dim tb As TextBox = CType(GridView1.FindControl("'FreeTextBox1'"),
    > TextBox)
    > Patrick
    >
    >
    >
    > "VB Programmer" <> wrote in message
    > news:...
    >>I have a gridview control with several data fields. When the user clicks
    >>'edit' for the row I want the user to be able to edit a particular text
    >>field. Under that 'edit' textbox is a button. When they click on the
    >>button it fills in the textbox with some standard text.
    >>
    >> Question: In the code for the button how do I reference the textbox
    >> 'FreeTextBox1' (for the current edit row)?
    >>
    >> Here's the gridview layout...
    >>
    >> <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
    >> AllowSorting="True"
    >> AutoGenerateColumns="False" CellPadding="4"
    >> DataKeyNames="ProductId" DataSourceID="sdsProducts"
    >> ForeColor="#333333" GridLines="None">
    >> <FooterStyle BackColor="#5D7B9D" Font-Bold="True"
    >> ForeColor="White" />
    >> <Columns>
    >> <asp:CommandField ShowDeleteButton="True"
    >> ShowEditButton="True" />
    >> <asp:TemplateField HeaderText="Category"
    >> SortExpression="CategoryId">
    >> <EditItemTemplate>
    >> <asp:DropDownList ID="ddlCategory" runat="server"
    >> DataSourceID="sdsCategory"
    >> DataTextField="CategoryName"
    >> DataValueField="CategoryId" SelectedValue='<%# Bind("CategoryId") %>' >
    >> </asp:DropDownList>
    >> </EditItemTemplate>
    >> <ItemTemplate>
    >> &nbsp;<asp:Label ID="Label1" runat="server" Text='<%#
    >> Bind("CategoryName") %>'></asp:Label>
    >> </ItemTemplate>
    >> </asp:TemplateField>
    >> <asp:BoundField DataField="ProductCode" HeaderText="Product
    >> Code" SortExpression="ProductCode" />
    >> <asp:BoundField DataField="ProductTitle" HeaderText="Title"
    >> SortExpression="ProductTitle" >
    >> <ItemStyle Width="200px" />
    >> </asp:BoundField>
    >> <asp:TemplateField HeaderText="Description"
    >> SortExpression="ProductDescription">
    >> <EditItemTemplate>
    >> <FTB:FreeTextBox ID="FreeTextBox1" runat="server"
    >> AllowHtmlMode="False" AssemblyResourceHandlerPath=""
    >> AutoConfigure=""
    >> AutoGenerateToolbarsFromString="True" AutoHideToolbar="True"
    >> AutoParseStyles="True" BackColor="158, 190, 245"
    >> BaseUrl="" BreakMode="Paragraph"
    >> ButtonDownImage="False" ButtonFileExtention="gif"
    >> ButtonFolder="Images" ButtonHeight="20"
    >> ButtonImagesLocation="InternalResource"
    >> ButtonOverImage="False" ButtonPath=""
    >> ButtonSet="Office2003" ButtonWidth="21"
    >> ClientSideTextChanged="" ConvertHtmlSymbolsToHtmlCodes="False"
    >> DesignModeBodyTagCssClass="" DesignModeCss=""
    >> DisableIEBackButton="False" DownLevelCols="50"
    >> DownLevelMessage="" DownLevelMode="TextArea"
    >> DownLevelRows="10" EditorBorderColorDark="128, 128, 128"
    >> EditorBorderColorLight="128, 128, 128"
    >> EnableHtmlMode="True" EnableSsl="False"
    >> EnableToolbars="True" Focus="False"
    >> FormatHtmlTagsToXhtml="True" GutterBackColor="129, 169, 226"
    >> GutterBorderColorDark="128, 128, 128"
    >> GutterBorderColorLight="255, 255, 255"
    >> Height="150px" HelperFilesParameters=""
    >> HelperFilesPath="" HtmlModeCss="" HtmlModeDefaultsToMonoSpaceFont="True"
    >> ImageGalleryPath="~/images/"
    >> ImageGalleryUrl="ftb.imagegallery.aspx?rif={0}&cif={0}"
    >> InstallationErrorMessage="InlineMessage"
    >> JavaScriptLocation="InternalResource"
    >> Language="en-US" PasteMode="Default"
    >> ReadOnly="False" RemoveScriptNameFromBookmarks="True"
    >> RemoveServerNameFromUrls="True"
    >> RenderMode="NotSet" ScriptMode="External" ShowTagPath="False"
    >> SslUrl="/." StartMode="DesignMode"
    >> StripAllScripting="False" SupportFolder="/aspnet_client/FreeTextBox/"
    >> TabIndex="-1" TabMode="InsertSpaces" Text='<%#
    >> Bind("ProductDescription") %>'
    >> TextDirection="LeftToRight"
    >> ToolbarBackColor="Transparent" ToolbarBackgroundImage="True"
    >> ToolbarImagesLocation="InternalResource"
    >> ToolbarLayout="ParagraphMenu,FontFacesMenu,FontSizesMenu,FontForeColorsMenu|Bold,Italic,Underline,Strikethrough;Superscript,Subscript,RemoveFormat|JustifyLeft,JustifyRight,JustifyCenter,JustifyFull;BulletedList,NumberedList,Indent,Outdent;CreateLink,Unlink,InsertImage,InsertRule|Cut,Copy,Paste;Undo,Redo,Print"
    >> ToolbarStyleConfiguration="NotSet"
    >> UpdateToolbar="True" UseToolbarBackGroundImage="True"
    >> Width="350px">
    >> </FTB:FreeTextBox>
    >> <asp:Button ID="cmdEditFreeShip" runat="server"
    >> OnClick="cmdEditFreeShip_Click" Text="Add Free Shipping" />
    >> </EditItemTemplate>
    >> <ItemStyle Width="200px" />
    >> <ItemTemplate>
    >> <asp:Label ID="Label2" runat="server" Text='<%#
    >> Bind("ProductDescription") %>'></asp:Label>
    >> </ItemTemplate>
    >> </asp:TemplateField>
    >> <asp:BoundField DataField="ProductPriceOriginal"
    >> HeaderText="Was Price" SortExpression="ProductPriceOriginal"
    >> DataFormatString="{0:c}" />
    >> <asp:BoundField DataField="ProductPrice" HeaderText="Price"
    >> SortExpression="ProductPrice" DataFormatString="{0:c}" />
    >> <asp:BoundField DataField="ProductPic" HeaderText="Image"
    >> SortExpression="ProductPic" />
    >> <asp:BoundField DataField="ProductId" HeaderText="ProductId"
    >> ReadOnly="True" SortExpression="ProductId"
    >> Visible="False" />
    >> </Columns>
    >> <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    >> <EditRowStyle BackColor="#999999" />
    >> <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True"
    >> ForeColor="#333333" />
    >> <PagerStyle BackColor="#284775" ForeColor="White"
    >> HorizontalAlign="Center" />
    >> <HeaderStyle BackColor="#5D7B9D" Font-Bold="True"
    >> ForeColor="White" />
    >> <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    >> </asp:GridView>
    >>

    >
    >
    VB Programmer, Aug 16, 2006
    #3
  4. VB Programmer

    tiopipen

    Joined:
    Mar 26, 2010
    Messages:
    1
    Patrick,
    I have tried this code but I cant get it to work.

    Dim tb As TextBox = CType(GridView1.FindControl("'FreeTextBox1'"), TextBox)

    it seems to me like I need something else to access the gridview in edit mode.
    do you have any ideas?
    thanks
    tiopipen
    tiopipen, Mar 26, 2010
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gnarlodious
    Replies:
    4
    Views:
    17,578
    elizas
    May 5, 2010
  2. John J Lee
    Replies:
    3
    Views:
    470
    bruno at modulix
    Dec 1, 2005
  3. Frank Kurka
    Replies:
    8
    Views:
    304
  4. Jaime Stuardo

    GridView control enters edit mode when I click Edit link twice

    Jaime Stuardo, Apr 7, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    392
    Jaime Stuardo
    Apr 7, 2006
  5. jobs at webdos
    Replies:
    0
    Views:
    463
    jobs at webdos
    Oct 9, 2006
Loading...

Share This Page