473,408 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Dropdown list within a datagrid

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.

Nov 19 '05 #1
7 3170
this is working code:
in .aspx file:

<asp:DropDownList Runat="server" ID="ddlSubcategories" DataTextField="Name"
DataValueField="ID" AutoPostBack="True"
OnSelectedIndexChanged="ddlSubcategories_SelectedI ndexChanged">
</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!
"gn@dana.ucc.nau.edu" wrote:
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.

Nov 19 '05 #2
Sorry, the code snippet in the code behind is:

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

"gn@dana.ucc.nau.edu" wrote:
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.

Nov 19 '05 #3
Did you set AutoPostBack = true ?

Eliyahu

<gn@dana.ucc.nau.edu> wrote in message
news:11*********************@c13g2000cwb.googlegro ups.com...
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.

Nov 19 '05 #4
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").ToStri ng)
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

Nov 19 '05 #5
Is ViewState enabled for the page?

Eliyahu

<gn@dana.ucc.nau.edu> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
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").ToStri ng)
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

Nov 19 '05 #6
gn
ViewState is enabled for the page, the datagrid and both dropdownlists,
still makes no difference

Nov 19 '05 #7
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_SelectedIndexChang ed"
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

Nov 19 '05 #8

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

Similar topics

0
by: Philip Townsend | last post by:
I have a datagrid that contains a dropdown list that is part of an EditItemTemplate. I need to run some code when the dropdown list builds in order to preselect an item in the list. Preselecting...
3
by: Big Dave | last post by:
I know it's been asked a million times before, but I still can't seem to find an answer that works. I've got a dropdown list in the footer template of a datagrid. The dropdown list databinds,...
1
by: Vijay Kerji | last post by:
Hi, I have a datagrid with dropdown list and Remove hyperlink in it as columns. When I remove a row from the datagrid, Dropdown list selection is retaining its previous value. i.e, removed...
6
by: Jenna Alten | last post by:
I have a datagrid with a template column that contains a dropdown list. I currently fill and display the dropdown list on the page load. This is working correctly. I am NOT using an Edit Column. I...
1
by: Andy | last post by:
Hello, I have a datagrid which contains DropDownList as follow: <Columns> <asp:TemplateColumn > <ItemTemplate> <asp:DropDownList id=ProductName...
2
by: Peter | last post by:
ASP.NET 2003 In the DataGrid how do I select current cell value in the dropdown box when I click on the edit link, currently when I click on the edit link in the DataGrid the dropdown box...
0
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
6
by: yasodhai | last post by:
Hi, I used a dropdown control which is binded to a datagrid control. I passed the values to the dropdownlist from the database using a function as follows in the aspx itself. <asp:DropDownList...
4
by: youvrajasnsm | last post by:
Hi All, >I am using datagrid control in asp.net with C#. >I have two dropdown list in datagrid e.g. one dropdown have Classname and another have Studentname. >now I want to show all the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.