473,434 Members | 1,834 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,434 software developers and data experts.

Can I use different data sources for each row in a given column (column type dropdownlist)

Hi
I have a aspx application written in c#.
I have created a datagrid control on the page.
One of the columns in the control is a dropdownlist.
I would like to set the data source of the dropdownlist to a different
recordset for each row.
How can I do this in C#?

I have used the ItemDataBound event, to set the DataSource for each row
of the dropdownlist.
Running the code in debug mode, I can see that the DataSource is being
reset, however, when my page comes up, there are two rows in the data
grid, both drop down lists have the same data source.

private void dgInvoiceList_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e )
{
DropDownList ddlCategory =
(DropDownList)e.Item.FindControl("ddlCategory");

switch ((int)(e.Item.ItemType))
{ {
case (int)ListItemType.Item :

if( (e.Item.Cells[13].Text ==
GTS.Common.GTSConsts.CostCategoryTypeCode_BookingE xtentionExpense) |
(e.Item.Cells[13].Text ==
GTS.Common.GTSConsts.CostCategoryTypeCode_BookingE xtensionInternalAir)
)
{
ddlCategory.DataSource = mdsCostCategories_Extensions.Tables[0];
ddlCategory.DataBind();
}
break;

case (int)ListItemType.AlternatingItem:
if( (e.Item.Cells[13].Text ==
GTS.Common.GTSConsts.CostCategoryTypeCode_BookingE xtentionExpense) |
(e.Item.Cells[13].Text ==
GTS.Common.GTSConsts.CostCategoryTypeCode_BookingE xtensionInternalAir)
)
{
ddlCategory.DataSource = mdsCostCategories_Extensions.Tables[0];
ddlCategory.DataBind();
}
break;
}
}

Jun 29 '06 #1
2 1401
What exactly is the problem? both dropdowns are bound to
mdsCostCategories_Extensions.Tables[0];
so obviously they will show the same data.

this one should help you understand the datagrid:
http://www.odetocode.com/Articles/231.aspx

za*******@gmail.com schreef:
Hi
I have a aspx application written in c#.
I have created a datagrid control on the page.
One of the columns in the control is a dropdownlist.
I would like to set the data source of the dropdownlist to a different
recordset for each row.
How can I do this in C#?

I have used the ItemDataBound event, to set the DataSource for each row
of the dropdownlist.
Running the code in debug mode, I can see that the DataSource is being
reset, however, when my page comes up, there are two rows in the data
grid, both drop down lists have the same data source.

private void dgInvoiceList_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e )
{
DropDownList ddlCategory =
(DropDownList)e.Item.FindControl("ddlCategory");

switch ((int)(e.Item.ItemType))
{ {
case (int)ListItemType.Item :

if( (e.Item.Cells[13].Text ==
GTS.Common.GTSConsts.CostCategoryTypeCode_BookingE xtentionExpense) |
(e.Item.Cells[13].Text ==
GTS.Common.GTSConsts.CostCategoryTypeCode_BookingE xtensionInternalAir)
)
{
ddlCategory.DataSource = mdsCostCategories_Extensions.Tables[0];
ddlCategory.DataBind();
}
break;

case (int)ListItemType.AlternatingItem:
if( (e.Item.Cells[13].Text ==
GTS.Common.GTSConsts.CostCategoryTypeCode_BookingE xtentionExpense) |
(e.Item.Cells[13].Text ==
GTS.Common.GTSConsts.CostCategoryTypeCode_BookingE xtensionInternalAir)
)
{
ddlCategory.DataSource = mdsCostCategories_Extensions.Tables[0];
ddlCategory.DataBind();
}
break;
}
}


Jun 29 '06 #2
There is another place in the code where all ddl's get set to
mdsCostCategories.Tables[0]
But then both ddl's are displaying mdsCostCategories.Tables[0] even tho
I have the code below in ItemDataBound. I know for the second row the
code is being executed cuz I run it in debug mode.

Robert wrote:
What exactly is the problem? both dropdowns are bound to
mdsCostCategories_Extensions.Tables[0];
so obviously they will show the same data.

this one should help you understand the datagrid:
http://www.odetocode.com/Articles/231.aspx

za*******@gmail.com schreef:
Hi
I have a aspx application written in c#.
I have created a datagrid control on the page.
One of the columns in the control is a dropdownlist.
I would like to set the data source of the dropdownlist to a different
recordset for each row.
How can I do this in C#?

I have used the ItemDataBound event, to set the DataSource for each row
of the dropdownlist.
Running the code in debug mode, I can see that the DataSource is being
reset, however, when my page comes up, there are two rows in the data
grid, both drop down lists have the same data source.

private void dgInvoiceList_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e )
{
DropDownList ddlCategory =
(DropDownList)e.Item.FindControl("ddlCategory");

switch ((int)(e.Item.ItemType))
{ {
case (int)ListItemType.Item :

if( (e.Item.Cells[13].Text ==
GTS.Common.GTSConsts.CostCategoryTypeCode_BookingE xtentionExpense) |
(e.Item.Cells[13].Text ==
GTS.Common.GTSConsts.CostCategoryTypeCode_BookingE xtensionInternalAir)
)
{
ddlCategory.DataSource = mdsCostCategories_Extensions.Tables[0];
ddlCategory.DataBind();
}
break;

case (int)ListItemType.AlternatingItem:
if( (e.Item.Cells[13].Text ==
GTS.Common.GTSConsts.CostCategoryTypeCode_BookingE xtentionExpense) |
(e.Item.Cells[13].Text ==
GTS.Common.GTSConsts.CostCategoryTypeCode_BookingE xtensionInternalAir)
)
{
ddlCategory.DataSource = mdsCostCategories_Extensions.Tables[0];
ddlCategory.DataBind();
}
break;
}
}


Jun 29 '06 #3

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

Similar topics

6
by: Ramon M. Felciano | last post by:
Helo all -- I'm trying to gain a deeper understand for what type of semi-declarative programming can be done through XML and XPath/XSLT. I'm looking at graph processing problems as a testbed for...
2
by: sunstarwu | last post by:
Hi, I am having difficultly being able to view certain Columns and rows via a DropDownList. Everytime I load my webpage.aspx it just shows empty drop down menus. I have no problem showing all...
0
by: Jonah Olsson | last post by:
Hi guys, Here's a problem: My customer needs a way to import small Excel/Access-files of data into their SQL Server. The data files all contains the same type of data; email address, first...
2
by: Dnna | last post by:
I have a table which is bound to an Internet Explorer XML data island. I'm using ASP.NET's client-side validators for an input field in the table. The problem is that if the input fields are in...
7
by: Mike P | last post by:
I am binding data to a datagrid, but there is 1 field that I need to use a separate query to populate. This is the field : <asp:TemplateColumn HeaderText="SIP Account/s" ItemStyle-Width="75px"...
9
by: Timm | last post by:
I have an ASP.NET 2.0 page with two DropDownLists. I am using declarative data binding wherever possible and trying to minimize the use of code. The list of values in DropDownList DDL2 should be...
17
by: romixnews | last post by:
Hi, I'm facing the problem of analyzing a memory allocation dynamic and object creation dynamics of a very big C++ application with a goal of optimizing its performance and eventually also...
5
by: rAinDeEr | last post by:
Hi, I have a web application with a table to store terms and conditions of a Company. This may some times run into many pages and some times it may be just a few sentences. It is a character...
3
by: Radu | last post by:
Hi. I have the following problem - I need to build a user-control in asp.net (an ascx) to somehow allow the users to search by first name or last name among a big (~10.000 records) email addresses...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
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
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,...
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...
1
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.