Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 15th, 2006, 04:06 PM
Registered User
 
Join Date: Mar 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Updating a textbox from DropDown selection

I have a DataGrid where, in the EditItemTemplate, one of the columns is a DropDownList and the next column is a textbox. I need to update the TextBox.Text when the DropDownList's selected item is changed.

The aspx page is similar to this:
<asp:datagrid id="grid" runat="server" AutoGenerateColumns="False">
    <Columns>
        <asp:TemplateColumn HeaderText="Product">
            <ItemTemplate><asp:Literal id="ltlProdName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ProductName") %>'></asp:Literal>
            </ItemTemplate>
            <EditItemTemplate><asp:DropDownList id="ddlProdName" runat=server AutoPostBack=True OnSelectedIndexChanged="DropDown_SelectedIndexChan ged"><asp:DropDownList>
            </EditItemTemplate>


And the aspx.cs page is like this:

protected void DropDown_SelectedIndexChanged(object sender, EventArgs e)
{
    DropDownList ddl = (DropDownList)sender;
    //*******Need to find the TextBox control from this row of the grid and update its .Text property*******
}

Not sure how to find that TextBox in the proper row of the DataGrid. It doesnt seem to fire the event either, and if I add a handler to the ItemDataBound of the datagrid, it throws an error that I referrence and object without specifying an instance...

Thanks for your help.
kj

 
Old March 15th, 2006, 04:34 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

To have the selectedindexchanged event fire you need to add this to the dropdownlist in the HTML:
   OnSelectedIndexChanged="DropDown_SelectedIndexChan ged"

You need to add this to the selectedindexchaned event of the ddl
   DataGridItem dgi = ((DataGridItem)(ddlEmployee.Parent.Parent));
   TextBox YourTextBox = dgi.FindControl("TheTextBox");


Jim

 
Old March 15th, 2006, 04:47 PM
Registered User
 
Join Date: Mar 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I had to do it as:

TextBox YourTextBox = (TextBox)dgi.FindControl("TheTextBox");

But that worked! Thanks very much, I've been beating my head against the wall for a few days on this because of that one stupid line:
DataGridItem dgi = ((DataGridItem)(ddlEmployee.Parent.Parent));

Thanks again!
kj

 
Old March 15th, 2006, 04:49 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

You are welcome. I have been playing around with the datagrid for some time. I found lots of examples on line, but I found that line to be confusing at first.. but very helpful.

Jim

 
Old November 7th, 2006, 04:04 AM
Registered User
 
Join Date: Mar 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i am having same problem with datagrid dropdownlist. I tried the above solution. But the problem with that solution is : the event fires for each and every dropdownlist control in the datagrid And not for the specific dropdownlist for which I change the selection at run time. didn't you come across this problem? is there any solution for this?
When the event fires, I need to get the itemindex of dropdownlist which fired this event. If you debug above code with f11/f10 then you will see the event firing for every item in the datagrid.
any resolution?

anil soman





Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Multiple selection DropDown surendran ASP.NET 2.0 Basics 1 September 26th, 2008 07:49 AM
DropDown Value Selection problem....... dharmeshtandel ASP.NET 2.0 Basics 0 May 15th, 2008 07:27 AM
Multi selection dropdown control ninel ASP.NET 1.0 and 1.1 Basics 1 March 8th, 2007 12:56 PM
Menu / Dropdown List Selection Reduction larry101 Javascript How-To 2 September 20th, 2004 03:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.