Link to home
Create AccountLog in
Avatar of Billy Ma
Billy MaFlag for Hong Kong

asked on

Table with dropdown list in C#.NET

How can I get the data from database
and then populate them into a table IN C#.NET?

I have got no problem on getting data, but just don't know how to populate into a table....seem no control can help on my requirement.

however, each cell in the table is a dropdown list.
if no data is found in the database, that dropdown list will be selected the first value
otherwise, it will be selected the value based on the data of that cell.

How to do this?
Avatar of Stephan_Schrandt
Stephan_Schrandt
Flag of Germany image

What's your VS version?
Avatar of Billy Ma

ASKER

Visual Web Developer 2010 Express
ASKER CERTIFIED SOLUTION
Avatar of Stephan_Schrandt
Stephan_Schrandt
Flag of Germany image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
yes, it's an ASP.NET application
can u give me a sample?
The c# code:

 
partial class _Default : System.Web.UI.Page
{
	protected System.Data.DataView dvCBO()
	{
		//get your combobox data here and return it as dataview
		//For this example we assume it has 2 fields, [ID] and [Name]
		//These fields will be the DataValueField and DatatextField for cbo
	}

	protected System.Data.DataView dvMain()
	{
		//return the data from main table here
		//For this example we assume the value we want to set in combobox is in field [cboValue]
		//If the field is not filled the combobox will show the default value
	}
	protected void Page_Load(object sender, System.EventArgs e)
	{
		if (!this.IsPostBack)
		{
			this.GridView1.DataSource = dvMain();
			this.GridView1.DataBind();
		}
	}
	public _Default()
	{
		Load += Page_Load;
	}
}

Open in new window


The markup:

 
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    	<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
			<Columns>
				<asp:TemplateField><ItemTemplate><asp:DropDownList ID="ddl1" runat="server" Width="300px" AppendDataBoundItems="True" DataSource="<%# dvCBO() %>" DataTextField="Name" DataValueField="ID" SelectedValue='<%# Eval("cboValue").ToString() %>'>
					<asp:ListItem Text="My default value" Value=""></asp:ListItem>
					</asp:DropDownList></ItemTemplate> </asp:TemplateField>
			</Columns>
		 </asp:GridView>
    </div>
    </form>
</body>
</html>

Open in new window

I need to have a loop
Get the Company
in each Company, I get the Risk Rating
and get the Process of that company
then get the year rating of each process (2008, 2009, 2010, 2011, 2012)
Please tell me your database type and the table structure.
Oracle 10 Express Edition
table.jpg
Sorry I don't understand. What do you want to diplay in the gridrows and what field in the combobox?
thanks