Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > dropdownlist, textbox in datagrid dropdownlist_selectedindexchange event

Reply
Thread Tools

dropdownlist, textbox in datagrid dropdownlist_selectedindexchange event

 
 
CindyH
Guest
Posts: n/a
 
      09-03-2007
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


 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      09-13-2007
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" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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
>
>



 
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
Why is a button Click event also called when a textbox TextChanged event is called??? S_K ASP .Net 6 11-08-2007 07:44 PM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net Building Controls 1 05-28-2004 06:23 AM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net 2 05-25-2004 11:45 PM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net Datagrid Control 0 05-25-2004 01:45 AM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net Web Controls 0 05-25-2004 01:45 AM



Advertisments