Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How reference text box in GridView while in edit mode?

Reply
Thread Tools

How reference text box in GridView while in edit mode?

 
 
VB Programmer
Guest
Posts: n/a
 
      08-15-2006
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>
<aspropDownList ID="ddlCategory" runat="server"
DataSourceID="sdsCategory"
DataTextField="CategoryName"
DataValueField="CategoryId" SelectedValue='<%# Bind("CategoryId") %>' >
</aspropDownList>
</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>


 
Reply With Quote
 
 
 
 
Patrick.O.Ige
Guest
Posts: n/a
 
      08-16-2006
Have you tried?
Dim tb As TextBox = CType(GridView1.FindControl("'FreeTextBox1'"), TextBox)
Patrick



"VB Programmer" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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>
> <aspropDownList ID="ddlCategory" runat="server"
> DataSourceID="sdsCategory"
> DataTextField="CategoryName"
> DataValueField="CategoryId" SelectedValue='<%# Bind("CategoryId") %>' >
> </aspropDownList>
> </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>
>



 
Reply With Quote
 
 
 
 
VB Programmer
Guest
Posts: n/a
 
      08-16-2006
Thanks Patrick. I assume that this will work based on the "current row"?

"Patrick.O.Ige" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Have you tried?
> Dim tb As TextBox = CType(GridView1.FindControl("'FreeTextBox1'"),
> TextBox)
> Patrick
>
>
>
> "VB Programmer" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>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>
>> <aspropDownList ID="ddlCategory" runat="server"
>> DataSourceID="sdsCategory"
>> DataTextField="CategoryName"
>> DataValueField="CategoryId" SelectedValue='<%# Bind("CategoryId") %>' >
>> </aspropDownList>
>> </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>
>>

>
>



 
Reply With Quote
 
tiopipen tiopipen is offline
Junior Member
Join Date: Mar 2010
Posts: 1
 
      03-26-2010
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
div box questions; float text around a box, fit box to image size Gnarlodious HTML 4 05-05-2010 11:30 AM
GridView edit validation, edit dropdown list, delete popup confirm =?Utf-8?B?a2Vu?= ASP .Net 1 01-23-2006 12:51 PM
Snapshot restraint - edit, edit, edit Alan Browne Digital Photography 24 05-10-2005 10:15 PM
Snapshot restraint - edit, edit, edit Patrick Digital Photography 0 05-06-2005 10:53 PM



Advertisments