473,594 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 selectedindexch anged event and that never fires.

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

Public Sub dataCOM_Selecte dIndexChanged(B yVal sender As Object, ByVal e
As System.EventArg s)
'populate second dropdownlist code
End Sub

This didn't fire either.

Any ideas or suggestions would be appreciated.

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

<asp:DropDownLi st Runat="server" ID="ddlSubcateg ories" DataTextField=" Name"
DataValueField= "ID" AutoPostBack="T rue"
OnSelectedIndex Changed="ddlSub categories_Sele ctedIndexChange d">
</asp:DropDownLis t>

protected void ddlCategories_S electedIndexCha nged(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.na u.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 selectedindexch anged event and that never fires.

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

Public Sub dataCOM_Selecte dIndexChanged(B yVal sender As Object, ByVal e
As System.EventArg s)
'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 ddlSubcategorie s_SelectedIndex Changed(object sender,
EventArgs e)
{
// the code goes here
}

"gn@dana.ucc.na u.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 selectedindexch anged event and that never fires.

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

Public Sub dataCOM_Selecte dIndexChanged(B yVal sender As Object, ByVal e
As System.EventArg s)
'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.na u.edu> wrote in message
news:11******** *************@c 13g2000cwb.goog legroups.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 selectedindexch anged event and that never fires.

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

Public Sub dataCOM_Selecte dIndexChanged(B yVal sender As Object, ByVal e
As System.EventArg s)
'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 OnSelectedIndex Changed, 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.EventArg s) Handles MyBase.Load
rtlTitle.Text = "Committees "
If Page.IsPostBack Then
Else
BindData("add")
End If
End Sub

Public Sub dataCOM_Selecte dIndexChanged(B yVal sender As Object, ByVal e
As System.EventArg s)
Dim objdr As OracleDataReade r
Dim objcnn As OracleConnectio n
Dim objcom As OracleCommand
Dim DDLAddCommName As DropDownList
objcnn = New
OracleConnectio n(Application(" gConnString").T oString)
objcnn.Open()
objcom = New OracleCommand(" SELECT COMMITTEE_NAME FROM
COMMITTEE " & _
"WHERE COMMITTEE_YEAR = '" & CommYear & "' ORDER BY
COMMITTEE_NAME" , objcnn)
objdr = objcom.ExecuteR eader
DDLAddCommName = CType(sender, DropDownList)
With DDLAddCommName
..DataSource = objdr
..DataTextField = "COMMITTEE_NAME "
..DataValueFiel d = "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.na u.edu> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com...
OK, It turns out the problem was OnSelectedIndex Changed, 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.EventArg s) Handles MyBase.Load
rtlTitle.Text = "Committees "
If Page.IsPostBack Then
Else
BindData("add")
End If
End Sub

Public Sub dataCOM_Selecte dIndexChanged(B yVal sender As Object, ByVal e
As System.EventArg s)
Dim objdr As OracleDataReade r
Dim objcnn As OracleConnectio n
Dim objcom As OracleCommand
Dim DDLAddCommName As DropDownList
objcnn = New
OracleConnectio n(Application(" gConnString").T oString)
objcnn.Open()
objcom = New OracleCommand(" SELECT COMMITTEE_NAME FROM
COMMITTEE " & _
"WHERE COMMITTEE_YEAR = '" & CommYear & "' ORDER BY
COMMITTEE_NAME" , objcnn)
objdr = objcom.ExecuteR eader
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="Tru e" BorderColor="#0 03399" AutoGenerateCol umns="False"
Width="90%" EditItemStyle-BackColor="#FFF FCC" EnableViewState ="True">
<EditItemStyl e BackColor="#FFF FCC"></EditItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="Whit e"
BackColor="#003 399"></HeaderStyle>
<Columns>
<asp:TemplateCo lumn HeaderText="Del ete">
<ItemTemplate >
<asp:LinkButt on CommandName="De lete" Text="Delete" ID="btnDel"
Runat="server" />
<INPUT id="hdnMemberID " type="hidden" value='<%#
Container.DataI tem("MEMBER_ID" ) %>' runat=server>
</ItemTemplate>
<FooterTemplate >
<asp:LinkButt on CommandName="In sert" Text="Add" ID="btnAdd"
Runat="server" />
</FooterTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="Yea r">
<ItemTemplate >
<%# Container.DataI tem("COMMITTEE_ YEAR") %>
</ItemTemplate>
<FooterTemplate >
<asp:DropDownLi st id="DDLAddCommY ear" runat="server"
OnSelectedIndex Changed="dataCO M_SelectedIndex Changed"
AutoPostBack="T rue" EnableViewState ="True"></asp:DropDownLis t>
</FooterTemplate>
<EditItemTempla te>
<asp:TextBox ID="txtCommYear " Columns="4" Text='<%#
Container.DataI tem("COMMITTEE_ YEAR") %> ' Runat="server" />
</EditItemTemplat e>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="Com mittee Name">
<ItemTemplate >
<%# Container.DataI tem("COMMITTEE_ NAME") %>
</ItemTemplate>
<FooterTemplate >
<asp:DropDownLi st id="DDLAddCommN ame" runat="server"
AutoPostBack="T rue" EnableViewState ="True"></asp:DropDownLis t>
</FooterTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="Nam e">
<ItemTemplate >
<%# Container.DataI tem("FIRST_NAME ") %>
<%# Container.DataI tem("LAST_NAME" ) %>
</ItemTemplate>
<FooterTemplate >
<asp:DropDownLi st id="DDLAddName "
runat="server"> </asp:DropDownLis t>
</FooterTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn Visible="False" >
<ItemTemplate >
<asp:TextBox ID="txtMemberID " Text='<%#
Container.DataI tem("MEMBER_ID" ) %>' Runat="server" />
</ItemTemplate>
</asp:TemplateCol umn>
</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
1618
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 the item is not the problem. The problem is that the dropdown object is not instantiated at the point at which the Edit button is clicked, or at any other obvious step in the process. In other words, when a user clicks the Edit (EditCommand)...
3
7304
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, but I can't seem to add a blank item to the top of the dropdown list. I've tried using the code to add this by placing it in both the page_load and the datagrid.itemDataBound event, but neither seems to work. I've also referenced the control by
1
1962
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 Dropdown item selection is applied to the next dropdown list. Is there any way to fix this problem?
6
5388
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 am receiving errors when trying to set the selected value of the dropdown within the ItemDataBound() subroutine. Below is the code I am using. I hope someone can tell me if this is possible. '''HTML''' <asp:datagrid id="dgAssignments"...
1
1575
by: Andy | last post by:
Hello, I have a datagrid which contains DropDownList as follow: <Columns> <asp:TemplateColumn > <ItemTemplate> <asp:DropDownList id=ProductName onSelectedIndexChanged=ProductName_IndexChange>....
2
2843
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 appears in the cell, but allways the first item in the dropdown box is shown not the current cell value? How do I make the current value in the cell automaticaly be selected in the dropdown box.
0
2903
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 strDataValueField; string strDataTextField; public CreateEditItemTemplateDDL(string DDLName,string DataValueField,string
6
5843
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 ID="FldType_add" Runat="server" DataSource='< %#GetFieldType()%>' DataValueField="Type" DataTextField="Type" /> Oce the page is loaded all the values are added to the dropdown list. But when I thought of getting the selected value from the...
4
1442
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 studentname in second dropdown related to their class selected in first dropdown. >plz help me in above. >Remember i am using both dropdown in a datagrid.......... Thanks.
0
8253
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8374
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8240
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6661
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5739
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3867
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2389
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
1
1482
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1216
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.