Changing template field in Gridview's currently edited row based on another template field

Hi, I have a gridview, and when editing a row I have some textboxes and a drop down list. I want to change the value (and perhaps activate) of one of the textboxes based on what is selected in the drop down list.

 So far I have got this far...


    Protected Sub DDLDynamicEdit_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

Dim ddl As DropDownList = CType(sender, DropDownList)

lblTemp.Text = CStr(ddl.SelectedItem.Text)

End Sub

I also turned on autopostback for this dropdownlist. This will change a textbox (lblError) on the page to the selected value of the dropdownlist when something is selected.

lblTemp is just a temporary textbox on the page, but I really want to change the value of a textbox on the same (currently edited) row of the gridview. Any ideas?

9/25/2007 8:47:57 AM 72751 articles. 3 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 41
Get it on Google Play
Get it on Apple App Store

You simply need to retrieve a reference to the GridViewRow containing your DropDownList and TextBox. 

Protected Sub DDLDynamicEdit_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
	Dim ddl As DropDownList = CType(sender, DropDownList)
	Dim gvr As GridViewRow = CType(ddl.NamingContainer, GridViewRow)
	Dim lblError As TextBox = CType(gvr.FindControl("lblError"), TextBox)

	If Not lblError Is Nothing Then
		lblError.Text = ddl.SelectedItem.Text
	End If
End Sub

Thanks, Ed

Microsoft MVP - ASP/ASP.NET

9/25/2007 12:44:52 PM

 Great reply, worked first time, thanks, you saved my bacon :)

9/25/2007 1:31:40 PM

Similar Artilces:

Help: Adding Dynamic Template to a GridView's template field.
I am creating a GridView control programatically. I run a database query and get back a DataTable. For each column found in the DataTable (the number of columns is not fixed in my case), I create a TemplateField and add the TemplateField to the Columns collection of the GridView. For the ItemTemplate of the Template Field, I created a class implementing the ITemplate interface. I added a Literal control in the 'InstantiateIn(Control container)' method of the class and then added the Literral control to the Container control's control collection. I also created a DataBinding event...

How to make the DetailsView's edit button visible according to the state of one field of a GridView's selected row?
Hello everyone! Now I am working with a Master/Detail page that using a gridview and a detailsview. The detailsview is set to editable and the edit button is autogenerated. I want to make the DetailsView's edit button visible according to the state of one field of a GridView's selected row. I tried to access the selected row of the gridview in the detailsview's ItemCreated event or DataBound event,using the following code GridViewRow row = gvwMaster.SelectedRow But it goes wrong with this line of code. And then I tried to write some code in the gridview's SelectedIndexChanged eve...

Can a field in Gridview be a Hyperlink field as well as Template field?
I have to add Template field  to Gridview and use data binding statement such as "<%# GetData(Eval("DType").ToString())%>" in the ItemTemplate. so that column retrieve/shows GetData("DType") values. When user clicks on this column it should redirect the user to another page, showing selected/clikced datarow . I think it is to do with Dynamic Hyperlink Field. I like to know can a column be a Hyperlink field as well as Template field so that i can use data binidng statement as above and do hyperlink task as well. your quick suggestion ...

Gridview dynamic template based on a field in the row
I need to change the itemtemplate based on a field in the table. i am developing a directory listing and I want to show different row layouts based on the subscription level Here is a little psuedo code describing what I want to do <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" AllowPaging="True" Width="760px" EmptyDataText="no data to show" ShowHeader="False" CellPadding="4" ForeColor="#333333" GridLines="None" > <Columns> <asp:TemplateField> Select case subscriptionlevel (<-- this is a field in the table) c...

Hiding a gridview row based on template field value
Here is my template field layout -    1 <asp:TemplateField HeaderText="Min Amount Due" > 2 <itemtemplate> 3 <asp:label id="lblAmtDue" runat="server" 4 text='<%# CheckItem(CheckItem1(Container.DataItem("emb"), Container.DataItem("prepay")), Container.DataItem("baldue"), Container.DataItem("cvalue"), Co...

Selecting Current Gridview Row fields with a template (button)
 Hii , I have a complex form where there are 2 fields for selection. This first is the gridview row select which is binded to a details view. Right next to it is another select button (template field). On its click I have to add the current gridview row's id and name to a list box which will then be saved to database on the save button click. I am having trouble getting the row fields on the template button click. I did a little research and found this to be useful. Its returning me the id of the current field but I need the other columns too but having some overload error. But...

Hide a hyperlink in a gridview template field based on row content
I need to find a way to hide a basic HTML hyperlink that is in a Gridview template field. The template field has two buttons (edit and cancel) and the hyperlink. The hyperlink take you to a second page that shows editorial detail. ll this works fine. The problem is I only want to display the hyperlink when the "Project Type" field = "Journal". I know how to refer to the Row using the "Row Data Bound" event but cannot find a way to show/hide the hyperlink. Code Behind: Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebCon...

Finding a control in GridView's Edit mode template
 Hi,I am using a GridView and in the Edit Tepmplate mode there is a text box and listbox. I would need to access the values in them from code behind. How can I actually do it? Can anyone help, please?Code is below.. I need to access the boxes after clicking on Search Button.                  <asp:TemplateField HeaderText="Coordinator"                     SortExpression="meeting_coordinator&qu...

Bookmarks Edit Dialog: "Tags Field" First Active Edit Field, *Not* the "Name Picker" Field. Can't be Changed in about:config
Name: Jimi Doe Product: Namoroka Summary: Bookmarks Edit Dialog: "Tags Field" First Active Edit Field, *Not* the "Name Picker" Field. Can't be Changed in about:config Comments: Problem --- When I want to bookmark a web page the tag field is always the first active field in the bookmark edit dialog, not the name field as it should be according to the standard behavior. If I change this via "about:config" my configuration lasts only for one bookmark. As of the second site I bookmark the configuration is reverted to "browser.bookmarks.editD...

Template Fields? Can I 'unconvert' them back to normal fields?
Template Fields? Can I 'unconvert' them back to normal fields? Or do i have to recreate them? The reason being is that I changed a field to a Template Field and Now my code fails to see the field: stUserFK = e.Row.Cells(1).TextThe above is now always "" now instead of the field's actual value  The Text property is always being returned as Sting.Empty because your value is now stored within a control inside of the cell. You can certainly revert back to a BoundField as long as your simply retrieving the data from the associated field. If you've custo...

Accessing Template Field's Textbox values from dynamically Created GridView
I Have Gridview in a wizard which will be created dynamically with dynamic item template fields. I don't have any problems in creation of dynamic gridview with textbox item templates. my problem is that in finish buttot event of wizard i am trying to access the values of gridview textboxs. in that finish button event boundcolumn values are coming but textbox control is getting null. is there any way to solve this problem i am creating dynamic template column in the following mannerpublic GridViewTemplate(ListItemType type, string colname, string colId ) {...

Programmatically reading the selected value of DropDownList in Gridview's Template field
Hi all, I'm reading the content of 2 fields in a Gridview programmatically. For text box, I'm successful with   inv1 = CType(GV_Rows(e.RowIndex).Cells(7).Controls(0), TextBox) follow by a=inv1.text for dropdownlist, I have problem. My code is: inv2 = CType(GV.Rows(e.RowIndex).Cells(6).Controls(0), DropDownList) b=inv2.SelectedValue.Trim  HOwever I run into error: "Unable to cast object of type UI.LiteralCOntrol to type WebControls.DropDownList" Plse help... THank you very much. TOny Instead of using inv2 = CType(GV.Rows(e.RowIndex).Cells(6).Controls(0)...

Gridview row editing fields based on row data
Is there a way to change row editable fields in a databound gridview based on the rows data. For example letting a user edit all his and his fellows fields but preventing him from changing specific fields in his boss data on the same gridview? Help will be great fully appreciated. Thanks If I understand what you are saying is that you want to only allow a user to Edit certain rows within the GridView. If so, yes, you certainly can do this. What I would do is hide/display the Edit Button for a row based on the user's role or permissions. This can easily be done via the RowDataBound e...

Is it possible to load default value when hitting the edit botton on a GridViews' template field???
I have a GridView which Im using to assign a closing date to some records.  Currently the defualt value of most of the records for the closingdate field is <NULL>, but I want  when the users hits the edit button in once selected the record, to load todays date as the default value for the closingdate field, insted of the <NULL> value.  Becasue that field is going to be readonly.  So, when the user hits the update botton the date will be always the current date.I was trying this: (but is not working) Try         ...

Web resources about - Changing template field in Gridview's currently edited row based on another template field -

Resources last updated: 12/4/2015 1:22:54 PM