Dropdown list within a datagrid

G

gn

Hi have a dropdown list within a datagrid, based on what is selected in
the list I want to populate another dropdownlist, the code to populate
the dropdownlists is not the problem, my problem is getting the code
behind to recognise that something has been selected.

I have tried using the selectedindexchanged event and that never fires.

I also added onselectchange="dataCOM_SelectedIndexChanged" attribute to
the dropdownlist and on the code behind page:

Public Sub dataCOM_SelectedIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs)
'populate second dropdownlist code
End Sub

This didn't fire either.

Any ideas or suggestions would be appreciated.
 
G

Guest

this is working code:
in .aspx file:

<asp:DropDownList Runat="server" ID="ddlSubcategories" DataTextField="Name"
DataValueField="ID" AutoPostBack="True"
OnSelectedIndexChanged="ddlSubcategories_SelectedIndexChanged">
</asp:DropDownList>

protected void ddlCategories_SelectedIndexChanged(object sender,
EventArgs e)
{
//the code goes here
}

Maybe you forgot the AutoPostBack property set to True, which is False by
default ?

Hope this helps!
 
G

Guest

Sorry, the code snippet in the code behind is:

protected void ddlSubcategories_SelectedIndexChanged(object sender,
EventArgs e)
{
// the code goes here
}
 
G

gn

OK, It turns out the problem was OnSelectedIndexChanged, I had
OnSelectedIndex instead, so now it fires just fine.

My next problem is that I thought it would be easy to populate the next
DDL, however that doesn't seem to be the case, not only do I not
succeed in populating the ddl, I also loose everything from the first??

Here is the relevant code, let me know if you need to know more:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
rtlTitle.Text = "Committees"
If Page.IsPostBack Then
Else
BindData("add")
End If
End Sub

Public Sub dataCOM_SelectedIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs)
Dim objdr As OracleDataReader
Dim objcnn As OracleConnection
Dim objcom As OracleCommand
Dim DDLAddCommName As DropDownList
objcnn = New
OracleConnection(Application("gConnString").ToString)
objcnn.Open()
objcom = New OracleCommand("SELECT COMMITTEE_NAME FROM
COMMITTEE " & _
"WHERE COMMITTEE_YEAR = '" & CommYear & "' ORDER BY
COMMITTEE_NAME", objcnn)
objdr = objcom.ExecuteReader
DDLAddCommName = CType(sender, DropDownList)
With DDLAddCommName
..DataSource = objdr
..DataTextField = "COMMITTEE_NAME"
..DataValueField = "COMMITTEE_NAME"
..DataBind()
End With
objcnn.Close()
End Sub

Thasnks again
 
G

gn

ViewState is enabled for the page, the datagrid and both dropdownlists,
still makes no difference
 
G

gn

Here is the datagrid on the aspx page:
<DIV align="center"><asp:datagrid id="DataCOM" runat="server"
ShowFooter="True" BorderColor="#003399" AutoGenerateColumns="False"
Width="90%" EditItemStyle-BackColor="#FFFFCC" EnableViewState="True">
<EditItemStyle BackColor="#FFFFCC"></EditItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White"
BackColor="#003399"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton CommandName="Delete" Text="Delete" ID="btnDel"
Runat="server" />
<INPUT id="hdnMemberID" type="hidden" value='<%#
Container.DataItem("MEMBER_ID") %>' runat=server>
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton CommandName="Insert" Text="Add" ID="btnAdd"
Runat="server" />
</FooterTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Year">
<ItemTemplate>
<%# Container.DataItem("COMMITTEE_YEAR") %>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList id="DDLAddCommYear" runat="server"
OnSelectedIndexChanged="dataCOM_SelectedIndexChanged"
AutoPostBack="True" EnableViewState="True"></asp:DropDownList>
</FooterTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtCommYear" Columns="4" Text='<%#
Container.DataItem("COMMITTEE_YEAR") %> ' Runat="server" />
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Committee Name">
<ItemTemplate>
<%# Container.DataItem("COMMITTEE_NAME") %>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList id="DDLAddCommName" runat="server"
AutoPostBack="True" EnableViewState="True"></asp:DropDownList>
</FooterTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Name">
<ItemTemplate>
<%# Container.DataItem("FIRST_NAME") %>
<%# Container.DataItem("LAST_NAME") %>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList id="DDLAddName"
runat="server"></asp:DropDownList>
</FooterTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn Visible="False">
<ItemTemplate>
<asp:TextBox ID="txtMemberID" Text='<%#
Container.DataItem("MEMBER_ID") %>' Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid></DIV>
Let me know if anything else would be useful
Thanks again
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top