G
Guest
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
ataGrid id="Datagrid2" runat="server" Cssclass="txtTen" Width="600px"
Height="35px" Font-Size="9px" Font-Names="Verdana"
AutoGenerateColumns="False" Visible="True" BackColor="#FCFBEB"
BorderColor="#FFC0C0">
<HeaderStyle Font-Size="9px" Font-Names="Verdana"
Font-Bold="True"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="Hotel Type">
<ItemTemplate>
<asp
ropDownList id="ddlhtype" runat="server" Font-Size="9px"
Font-Names="Verdana" Width="100px" AutoPostBack="true" >
<asp:ListItem Value="Hotel Type">Hotel Type</asp:ListItem>
</asp
ropDownList>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Hotel name">
<ItemTemplate>
<asp
ropDownList id="ddlhname" runat="server" Font-Size="9px"
Font-Names="Verdana" Width="100px"></asp
ropDownList>
</ItemTemplate>
</asp:TemplateColumn>
</asp
ataGrid>
my code behind for the grid goes like this
Private Sub Datagrid2_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles Datagrid2.ItemCreated
If Not e.Item.FindControl("ddlhtype") Is Nothing Then
AddHandler CType(e.Item.FindControl("ddlhtype"),
DropDownList).SelectedIndexChanged, AddressOf GetHotelNames
End If
End Sub
the handler definition goes like this
Public Sub GetHotelNames(ByVal sender As Object, ByVal e As EventArgs)
Try
Dim quotemgr As New QuotationManager
Dim objcitystop As New CitystopServicesBE
objcitystop.ServiceCode = "CITYSTOP"
objcitystop.detailcode = "HTNM"
If Not CType(Datagrid2.FindControl("ddlhtype"), DropDownList) Is
Nothing Then
Dim strname As String
strname = CType(sender, DropDownList).SelectedValue.ToString()
objcitystop.Filter = strname
Dim col As New Collection
If Not CType(e.Item.FindControl("ddlhtype"),
DropDownList) Is Nothing Then
col = quotemgr.getcitystopdetails(objcitystop)
Dim objcity As CitystopServicesBE
For Each objcity In col
Dim strcode As New ListItem
strcode.Text = objcity.desc
strcode.Value = objcity.serviceid
Response.Write("before ddlname <br>")
If Not CType(Datagrid2.FindControl("ddlhname"),
DropDownList) Is Nothing Then
CType(Datagrid2.FindControl("ddlhname"),
DropDownList).Items.Add(strcode)
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
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

Height="35px" Font-Size="9px" Font-Names="Verdana"
AutoGenerateColumns="False" Visible="True" BackColor="#FCFBEB"
BorderColor="#FFC0C0">
<HeaderStyle Font-Size="9px" Font-Names="Verdana"
Font-Bold="True"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="Hotel Type">
<ItemTemplate>
<asp

Font-Names="Verdana" Width="100px" AutoPostBack="true" >
<asp:ListItem Value="Hotel Type">Hotel Type</asp:ListItem>
</asp

</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Hotel name">
<ItemTemplate>
<asp

Font-Names="Verdana" Width="100px"></asp

</ItemTemplate>
</asp:TemplateColumn>
</asp

my code behind for the grid goes like this
Private Sub Datagrid2_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles Datagrid2.ItemCreated
If Not e.Item.FindControl("ddlhtype") Is Nothing Then
AddHandler CType(e.Item.FindControl("ddlhtype"),
DropDownList).SelectedIndexChanged, AddressOf GetHotelNames
End If
End Sub
the handler definition goes like this
Public Sub GetHotelNames(ByVal sender As Object, ByVal e As EventArgs)
Try
Dim quotemgr As New QuotationManager
Dim objcitystop As New CitystopServicesBE
objcitystop.ServiceCode = "CITYSTOP"
objcitystop.detailcode = "HTNM"
If Not CType(Datagrid2.FindControl("ddlhtype"), DropDownList) Is
Nothing Then
Dim strname As String
strname = CType(sender, DropDownList).SelectedValue.ToString()
objcitystop.Filter = strname
Dim col As New Collection
If Not CType(e.Item.FindControl("ddlhtype"),
DropDownList) Is Nothing Then
col = quotemgr.getcitystopdetails(objcitystop)
Dim objcity As CitystopServicesBE
For Each objcity In col
Dim strcode As New ListItem
strcode.Text = objcity.desc
strcode.Value = objcity.serviceid
Response.Write("before ddlname <br>")
If Not CType(Datagrid2.FindControl("ddlhname"),
DropDownList) Is Nothing Then
CType(Datagrid2.FindControl("ddlhname"),
DropDownList).Items.Add(strcode)
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