473,573 Members | 3,876 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dependent DropDownList in DataGrid

Hello,

I have a datagrid with only one row and its having 2 dropdownlists, I need
to populate the secodn dropdownlist on the basis of the selection in the
first dropdown. but I am not able to populate the second dropdown, as its not
bale to find the specified control, even though the dropdownlist with the
specified name exists in the datagrid.

my .aspx page code goes like this

<asp:DataGrid id="Datagrid2" runat="server" Cssclass="txtTe n" Width="600px"
Height="35px" Font-Size="9px" Font-Names="Verdana"
AutoGenerateCol umns="False" Visible="True" BackColor="#FCF BEB"
BorderColor="#F FC0C0">

<HeaderStyle Font-Size="9px" Font-Names="Verdana"
Font-Bold="True"></HeaderStyle>

<Columns>
<asp:TemplateCo lumn HeaderText="Hot el Type">
<ItemTemplate >
<asp:DropDownLi st id="ddlhtype" runat="server" Font-Size="9px"
Font-Names="Verdana" Width="100px" AutoPostBack="t rue" >
<asp:ListItem Value="Hotel Type">Hotel Type</asp:ListItem>
</asp:DropDownLis t>
</ItemTemplate>
</asp:TemplateCol umn>

<asp:TemplateCo lumn HeaderText="Hot el name">
<ItemTemplate >
<asp:DropDownLi st id="ddlhname" runat="server" Font-Size="9px"
Font-Names="Verdana" Width="100px"></asp:DropDownLis t>
</ItemTemplate>
</asp:TemplateCol umn>
</asp:DataGrid>

my code behind for the grid goes like this
Private Sub Datagrid2_ItemC reated(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data GridItemEventAr gs) Handles Datagrid2.ItemC reated

If Not e.Item.FindCont rol("ddlhtype") Is Nothing Then
AddHandler CType(e.Item.Fi ndControl("ddlh type"),
DropDownList).S electedIndexCha nged, AddressOf GetHotelNames
End If

End Sub

the handler definition goes like this
Public Sub GetHotelNames(B yVal sender As Object, ByVal e As EventArgs)
Try
Dim quotemgr As New QuotationManage r
Dim objcitystop As New CitystopService sBE
objcitystop.Ser viceCode = "CITYSTOP"
objcitystop.det ailcode = "HTNM"

If Not CType(Datagrid2 .FindControl("d dlhtype"), DropDownList) Is
Nothing Then
Dim strname As String
strname = CType(sender, DropDownList).S electedValue.To String()
objcitystop.Fil ter = strname

Dim col As New Collection
If Not CType(e.Item.Fi ndControl("ddlh type"),
DropDownList) Is Nothing Then

col = quotemgr.getcit ystopdetails(ob jcitystop)
Dim objcity As CitystopService sBE
For Each objcity In col
Dim strcode As New ListItem
strcode.Text = objcity.desc
strcode.Value = objcity.service id
Response.Write( "before ddlname <br>")

If Not CType(Datagrid2 .FindControl("d dlhname"),
DropDownList) Is Nothing Then
CType(Datagrid2 .FindControl("d dlhname"),
DropDownList).I tems.Add(strcod e)
End If
Next
End If

Catch ex As Exception
Response.Write( ex.ToString)
End Try

but I am surprised to find that , it doesnt find both the mentioned
dropdowns, Can you pls tell me where I am going wrong.

Your expert advise would be highly appreciated.

Rgds
Shiju
Nov 18 '05 #1
2 2385
Shiju,
Once you are in your GetHotelNames method you can get a reference to either
dropdownlist like so:

dim htype as DropDownList = ctype(sender, DropDownList)
dim hValue as DropDownList = ctype(ctype(hty pe.Parent.Paren t,
DataGridITem).F indControl("ddl HValue"), DropdownList)

Those that help?

Karl

"Shiju Poyilil" <Sh**********@d iscussions.micr osoft.com> wrote in message
news:F1******** *************** ***********@mic rosoft.com...
Hello,

I have a datagrid with only one row and its having 2 dropdownlists, I need
to populate the secodn dropdownlist on the basis of the selection in the
first dropdown. but I am not able to populate the second dropdown, as its not bale to find the specified control, even though the dropdownlist with the
specified name exists in the datagrid.

my .aspx page code goes like this

<asp:DataGrid id="Datagrid2" runat="server" Cssclass="txtTe n" Width="600px" Height="35px" Font-Size="9px" Font-Names="Verdana"
AutoGenerateCol umns="False" Visible="True" BackColor="#FCF BEB"
BorderColor="#F FC0C0">

<HeaderStyle Font-Size="9px" Font-Names="Verdana"
Font-Bold="True"></HeaderStyle>

<Columns>
<asp:TemplateCo lumn HeaderText="Hot el Type">
<ItemTemplate >
<asp:DropDownLi st id="ddlhtype" runat="server" Font-Size="9px"
Font-Names="Verdana" Width="100px" AutoPostBack="t rue" >
<asp:ListItem Value="Hotel Type">Hotel Type</asp:ListItem>
</asp:DropDownLis t>
</ItemTemplate>
</asp:TemplateCol umn>

<asp:TemplateCo lumn HeaderText="Hot el name">
<ItemTemplate >
<asp:DropDownLi st id="ddlhname" runat="server" Font-Size="9px"
Font-Names="Verdana" Width="100px"></asp:DropDownLis t>
</ItemTemplate>
</asp:TemplateCol umn>
</asp:DataGrid>

my code behind for the grid goes like this
Private Sub Datagrid2_ItemC reated(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data GridItemEventAr gs) Handles Datagrid2.ItemC reated
If Not e.Item.FindCont rol("ddlhtype") Is Nothing Then
AddHandler CType(e.Item.Fi ndControl("ddlh type"),
DropDownList).S electedIndexCha nged, AddressOf GetHotelNames
End If

End Sub

the handler definition goes like this
Public Sub GetHotelNames(B yVal sender As Object, ByVal e As EventArgs)
Try
Dim quotemgr As New QuotationManage r
Dim objcitystop As New CitystopService sBE
objcitystop.Ser viceCode = "CITYSTOP"
objcitystop.det ailcode = "HTNM"

If Not CType(Datagrid2 .FindControl("d dlhtype"), DropDownList) Is
Nothing Then
Dim strname As String
strname = CType(sender, DropDownList).S electedValue.To String()
objcitystop.Fil ter = strname

Dim col As New Collection
If Not CType(e.Item.Fi ndControl("ddlh type"),
DropDownList) Is Nothing Then

col = quotemgr.getcit ystopdetails(ob jcitystop)
Dim objcity As CitystopService sBE
For Each objcity In col
Dim strcode As New ListItem
strcode.Text = objcity.desc
strcode.Value = objcity.service id
Response.Write( "before ddlname <br>")

If Not CType(Datagrid2 .FindControl("d dlhname"),
DropDownList) Is Nothing Then
CType(Datagrid2 .FindControl("d dlhname"), DropDownList).I tems.Add(strcod e)
End If
Next
End If

Catch ex As Exception
Response.Write( ex.ToString)
End Try

but I am surprised to find that , it doesnt find both the mentioned
dropdowns, Can you pls tell me where I am going wrong.

Your expert advise would be highly appreciated.

Rgds
Shiju

Nov 18 '05 #2
Thanks Karl , It really worked for me.

Rgds
Shiju

"Karl" wrote:
Shiju,
Once you are in your GetHotelNames method you can get a reference to either
dropdownlist like so:

dim htype as DropDownList = ctype(sender, DropDownList)
dim hValue as DropDownList = ctype(ctype(hty pe.Parent.Paren t,
DataGridITem).F indControl("ddl HValue"), DropdownList)

Those that help?

Karl

"Shiju Poyilil" <Sh**********@d iscussions.micr osoft.com> wrote in message
news:F1******** *************** ***********@mic rosoft.com...
Hello,

I have a datagrid with only one row and its having 2 dropdownlists, I need
to populate the secodn dropdownlist on the basis of the selection in the
first dropdown. but I am not able to populate the second dropdown, as its

not
bale to find the specified control, even though the dropdownlist with the
specified name exists in the datagrid.

my .aspx page code goes like this

<asp:DataGrid id="Datagrid2" runat="server" Cssclass="txtTe n"

Width="600px"
Height="35px" Font-Size="9px" Font-Names="Verdana"
AutoGenerateCol umns="False" Visible="True" BackColor="#FCF BEB"
BorderColor="#F FC0C0">

<HeaderStyle Font-Size="9px" Font-Names="Verdana"
Font-Bold="True"></HeaderStyle>

<Columns>
<asp:TemplateCo lumn HeaderText="Hot el Type">
<ItemTemplate >
<asp:DropDownLi st id="ddlhtype" runat="server" Font-Size="9px"
Font-Names="Verdana" Width="100px" AutoPostBack="t rue" >
<asp:ListItem Value="Hotel Type">Hotel Type</asp:ListItem>
</asp:DropDownLis t>
</ItemTemplate>
</asp:TemplateCol umn>

<asp:TemplateCo lumn HeaderText="Hot el name">
<ItemTemplate >
<asp:DropDownLi st id="ddlhname" runat="server" Font-Size="9px"
Font-Names="Verdana" Width="100px"></asp:DropDownLis t>
</ItemTemplate>
</asp:TemplateCol umn>
</asp:DataGrid>

my code behind for the grid goes like this
Private Sub Datagrid2_ItemC reated(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data GridItemEventAr gs) Handles

Datagrid2.ItemC reated

If Not e.Item.FindCont rol("ddlhtype") Is Nothing Then
AddHandler CType(e.Item.Fi ndControl("ddlh type"),
DropDownList).S electedIndexCha nged, AddressOf GetHotelNames
End If

End Sub

the handler definition goes like this
Public Sub GetHotelNames(B yVal sender As Object, ByVal e As EventArgs)
Try
Dim quotemgr As New QuotationManage r
Dim objcitystop As New CitystopService sBE
objcitystop.Ser viceCode = "CITYSTOP"
objcitystop.det ailcode = "HTNM"

If Not CType(Datagrid2 .FindControl("d dlhtype"), DropDownList) Is
Nothing Then
Dim strname As String
strname = CType(sender, DropDownList).S electedValue.To String()
objcitystop.Fil ter = strname

Dim col As New Collection
If Not CType(e.Item.Fi ndControl("ddlh type"),
DropDownList) Is Nothing Then

col = quotemgr.getcit ystopdetails(ob jcitystop)
Dim objcity As CitystopService sBE
For Each objcity In col
Dim strcode As New ListItem
strcode.Text = objcity.desc
strcode.Value = objcity.service id
Response.Write( "before ddlname <br>")

If Not CType(Datagrid2 .FindControl("d dlhname"),
DropDownList) Is Nothing Then

CType(Datagrid2 .FindControl("d dlhname"),
DropDownList).I tems.Add(strcod e)
End If
Next
End If

Catch ex As Exception
Response.Write( ex.ToString)
End Try

but I am surprised to find that , it doesnt find both the mentioned
dropdowns, Can you pls tell me where I am going wrong.

Your expert advise would be highly appreciated.

Rgds
Shiju


Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
2772
by: Stanley J Mroczek | last post by:
How do you load a dropdownlist when edit is clicked in a datagrid ? <Columns> <asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True" HeaderText="Option Description"></asp:BoundColumn> <asp:TemplateColumn runat="server" HeaderText="Id Type Option" "> <itemtemplate> <asp:label runat="server" Text='<%#...
2
16985
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of the columns of the data grid contains a DropDownlist. I managed to create this datagrid control as follows.
0
4782
by: Shane O. Pinnell | last post by:
I am sure this has come up before, but I haven't been able to find an answer as of yet. That said, any help is definitely appreciated! I have a datagrid populated from a dataset. I have a TemplateColumn with a DropDownList (DDL) in the FooterItemTemplate that is populated in the Page_Load event using a Sub Routine as the DataSource of the DDL....
1
1706
by: m3ckon | last post by:
Hi there, please help if you can, I'm having an issue with droponnlists in a datagrid I have a datagrid which is populated from a query .. all works fine I've added two extra columns, one is a dropdownlist and the other is a button which runs the command selectcode for this:
3
4364
by: Tim::.. | last post by:
Can someone please tell me how I go about preselecting an item in a drop drown list when I click the Edit Command in a datagrid? I have tried the following but it doesn't work for me! I would be really grateful for any assistance! Thanks
0
1817
by: Daniel Doyle | last post by:
Hello and apologies in advance for the amount of code in this post. I've also sent this message to the Sharepoint group, but thought that ASP.NET developers may also be able to help, even though it's a Sharepoint WebPart. I'm trying to do something fairly simple, create a datagrid that displays where and when a person works and allows them to...
4
2005
by: Mark Waser | last post by:
I've discovered a very odd bug when attempting to put a dropdown list in a datagrid. In the page PreRender step, the selected index of the datagrid is successfully set during databinding. Yet, when the datagrid enters it's own OnPreRender, the selected index has reverted to zero. I created a debug version of the dropdown list which...
15
3087
by: glenn | last post by:
Hi folks, I have a DropDownList in a DataGrid that is populated from records in a database. I want to add a value that might be a string such as "Select a Company" for the first item since an OnSelectedIndex event is not fired if you select the first item. Does anyone know of an easy way to do this?
1
1887
by: joethika | last post by:
i have a problem in asp.net.i don't know how to add dependent dropdownlist within the datagrid in asp.net using c# code.that is one dropdownlist is dependent on another within the datagrid.pls help me.
0
7789
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7707
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7800
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6432
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5605
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3737
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3743
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2227
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.