473,387 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How reference text box in GridView while in edit mode?

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,FontSiz esMenu,FontForeColorsMenu|Bold,Italic,Underline,St rikethrough;Superscript,Subscript,RemoveFormat|Jus tifyLeft,JustifyRight,JustifyCenter,JustifyFull;Bu lletedList,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>
Aug 15 '06 #1
2 3786
Have you tried?
Dim tb As TextBox = CType(GridView1.FindControl("'FreeTextBox1'"), TextBox)
Patrick

"VB Programmer" <do**********@somewhere.comwrote in message
news:OP**************@TK2MSFTNGP06.phx.gbl...
>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,FontSiz esMenu,FontForeColorsMenu|Bold,Italic,Underline,St rikethrough;Superscript,Subscript,RemoveFormat|Jus tifyLeft,JustifyRight,JustifyCenter,JustifyFull;Bu lletedList,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>

Aug 16 '06 #2
Thanks Patrick. I assume that this will work based on the "current row"?

"Patrick.O.Ige" <na********@hotmail.comwrote in message
news:uK**************@TK2MSFTNGP02.phx.gbl...
Have you tried?
Dim tb As TextBox = CType(GridView1.FindControl("'FreeTextBox1'"),
TextBox)
Patrick

"VB Programmer" <do**********@somewhere.comwrote in message
news:OP**************@TK2MSFTNGP06.phx.gbl...
>>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}&ci f={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,FontSi zesMenu,FontForeColorsMenu|Bold,Italic,Underline,S trikethrough;Superscript,Subscript,RemoveFormat|Ju stifyLeft,JustifyRight,JustifyCenter,JustifyFull;B ulletedList,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>


Aug 16 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John A Grandy | last post by:
I'm not using SqlDataSource or ObjectDataSource. I'm handling events , similar to approach commonly used in 1.1. DataGrid. My question is : How do I configure a GridView's edit mode row format ?...
3
by: misiek | last post by:
Hi all. I have following problem: 1. In my web page I have a GridView control, which does not have a DataSourceId set in designer. 2. When user presses Start button then I create...
4
by: | last post by:
I wanted better control over the display of the command buttons, so I created Template columns for each command. (Otherwise the GridView was putting extras spacing around the images and such.) ...
6
by: Scott McDaniel | last post by:
I'm using Visual Studio 2005 with the .NET 2.0.50727 framework, and we're using the standard Datagrid control bound to a SQL Server. We have two groups of users - "full edit" users, and "view...
3
by: cpnet | last post by:
I have a GridView which I'm populating from an ObjectDataSource (give the GridView a DataTable). The GridView will have about 20 rows, and only one editable column. The editable column consists...
0
by: Larry Bud | last post by:
After spending two days looking at the options in adding a row to a gridview, I came up with my own that I'd like to share. I only can share pseudo-code right now, but maybe in the future I'll...
4
by: Ben | last post by:
Hi, i try to change the display value of a radiobuttonlist embedded in a gridview, but only in normal mode. In edit mode, the radiobuttonlist must appears. With this code below, i get what i...
3
by: =?Utf-8?B?V2FubmFiZQ==?= | last post by:
I have a gridview that uses a sqldatasource. The rows of the gridview are editable. When the gridview is in edit mode, one of the columns is a dropdown. In testing the editing, I deleted the...
15
JustRun
by: JustRun | last post by:
I have a problem with the select option at the gridview and gonna pull my hair out cause it doesn't work at all. Here is the Grid view code: I want to get the selected row when the user click...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.