Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Web Controls (http://www.velocityreviews.com/forums/f63-asp-net-web-controls.html)
-   -   dropdownlist, textbox in datagrid dropdownlist_selectedindexchange event (http://www.velocityreviews.com/forums/t780161-dropdownlist-textbox-in-datagrid-dropdownlist_selectedindexchange-event.html)

CindyH 09-03-2007 05:19 PM

dropdownlist, textbox in datagrid dropdownlist_selectedindexchange event
 
Hi
I'm using vs.net 2003.
I have a dropdownlist inside a datagrid.
I would like to be able to select a value from the dropdownlist and then
have a textbox which is also inside the datagrid filled with that value.

I'm calling OnSelectedIndexChanged="ddlGridMonth_SelectedIndex Changed" event
when an item from the dropdownlist is selected

I'm not sure of the code I should be using for this event.
Right now I'm trying something like this:


Dim ddl As DropDownList = CType(sender, DropDownList)

Dim dg As DataGrid = Me.FindControl("dgMonthlyReports")

' not getting anything in this textbox (nothing)

Dim txt As TextBox = CType(dg.FindControl("ReportMonth"), TextBox)

' getting value from dropdownlist

Dim ddlValue As Integer = ddl.SelectedItem.Value

' not getting value here because it doesn't seem to know about the textbox

Dim TextValue As String = txt.Text

If ddlValue <> 0 Then

txt.Text = ddlValue

End If


I'm getting the value of the dropdownlist, but not the textbox and then I
need to see if the dropdownlist value is something other then 0 and if so
write the value to the textbox.

Thanks,

CindyH



Teemu Keiski 09-13-2007 05:57 PM

Re: dropdownlist, textbox in datagrid dropdownlist_selectedindexchange event
 
Hi,

you probably mean something like this

Dim ddl As DropDownList = CType(sender, DropDownList)

'NOTE THIS LINE
Dim gridItem As DataGridItem = CType(ddl.NamingContainer, DataGridItem)

Dim txt As TextBox = CType(gridItem.FindControl("ReportMonth"), TextBox)
Dim ddlValue As Integer = ddl.SelectedItem.Value
Dim TextValue As String = txt.Text



Point is NamingContainer of DroPDownList returns the DataGridItem which
represents the row the DDL is on. So running FindControl to this, will get
you controls on the same row

I've exlained this in a blog post:

Understanding the naming container hierarchy of ASP.NET databound controls
http://aspadvice.com/blogs/joteke/ar...-controls.aspx

-
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net



>
> Dim dg As DataGrid = Me.FindControl("dgMonthlyReports")
>
> ' not getting anything in this textbox (nothing)
>
> Dim txt As TextBox = CType(dg.FindControl("ReportMonth"), TextBox)
>
> ' getting value from dropdownlist
>
> Dim ddlValue As Integer = ddl.SelectedItem.Value
>
> ' not getting value here because it doesn't seem to know about the textbox
>
> Dim TextValue As String = txt.Text



"CindyH" <chenschel@new.rr.com> wrote in message
news:%23nU6e6k7HHA.4304@TK2MSFTNGP03.phx.gbl...
> Hi
> I'm using vs.net 2003.
> I have a dropdownlist inside a datagrid.
> I would like to be able to select a value from the dropdownlist and then
> have a textbox which is also inside the datagrid filled with that value.
>
> I'm calling OnSelectedIndexChanged="ddlGridMonth_SelectedIndex Changed"
> event
> when an item from the dropdownlist is selected
>
> I'm not sure of the code I should be using for this event.
> Right now I'm trying something like this:
>
>
> Dim ddl As DropDownList = CType(sender, DropDownList)
>
> Dim dg As DataGrid = Me.FindControl("dgMonthlyReports")
>
> ' not getting anything in this textbox (nothing)
>
> Dim txt As TextBox = CType(dg.FindControl("ReportMonth"), TextBox)
>
> ' getting value from dropdownlist
>
> Dim ddlValue As Integer = ddl.SelectedItem.Value
>
> ' not getting value here because it doesn't seem to know about the textbox
>
> Dim TextValue As String = txt.Text
>
> If ddlValue <> 0 Then
>
> txt.Text = ddlValue
>
> End If
>
>
> I'm getting the value of the dropdownlist, but not the textbox and then I
> need to see if the dropdownlist value is something other then 0 and if so
> write the value to the textbox.
>
> Thanks,
>
> CindyH
>
>





All times are GMT. The time now is 02:26 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57