How reference text box in GridView while in edit mode?

V

VB Programmer

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

Patrick.O.Ige

Have you tried?
Dim tb As TextBox = CType(GridView1.FindControl("'FreeTextBox1'"), TextBox)
Patrick
 
Joined
Mar 26, 2010
Messages
1
Reaction score
0
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top