Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 13th, 2008, 10:30 AM
Authorized User
Points: 169, Level: 3
Points: 169, Level: 3 Points: 169, Level: 3 Points: 169, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2008
Location: Northampton, , United Kingdom.
Posts: 35
Thanks: 1
Thanked 0 Times in 0 Posts
Default Databound Dropdown

We have a datagrid which is bound to a recordset and a template column containing a dropdown list of options (also bound to a recordset) and is rather similar to the example on the following page, with the exception that the dropdown is permanently visible.

http://aspnet.4guysfromrolla.com/demos/dgExample15.aspx

What I need is to set the value of the dropdown, based on one of the columns in the main datagrid.

MAIN TABLE
Name
Subject
Date
CategoryID

CATEGORY TABLE
CategoryID
Description

So, you can see that the dropdown contains the data from the category table, but the default/selected value on each row should be based on the CategoryID from the main table.

Any ideas on how to achieve this?

Regards,

Sean
__________________
Regards,

Sean
 
Old June 19th, 2008, 11:50 AM
rlb rlb is offline
Authorized User
 
Join Date: Jan 2007
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Something like this?

Code:
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            uxMyDropDown.DataSource = GetTheData();
            uxMyDropDown.DataTextField = "Description";
            uxMyDropDown.DataValueField = "CategoryID";
            uxMyDropDown.DataBind();
            uxMyDropDown.Items.Insert(0, new ListItem("Select One ...", "0")); //if you like...
        }
    }

        public DataSet GetTheData()
        {
            SqlConnection con = new SqlConnection("...");
            con.Open();
            DataSet theDataSet = new DataSet("marital");
            try
            {
                string sql = "SELECT * FROM CATEGORY_TABLE";
                SqlCommand cmd = new SqlCommand(sql, con);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(theDataSet);
                da.Dispose();
                cmd.Dispose();
                return theDataSet;
            }
            catch (Exception ex)
            {
                return theDataSet;
            }
            con.Close();
            con.Dispose();
        }
 
Old June 20th, 2008, 02:33 AM
Authorized User
Points: 169, Level: 3
Points: 169, Level: 3 Points: 169, Level: 3 Points: 169, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2008
Location: Northampton, , United Kingdom.
Posts: 35
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Not quite,

The main datagrid will have columns for the following:

(1) MAIN.Name
(2) MAIN.Subject
(3) MAIN.Date
(4) Dropdown Selection, containing:
    (A) CATEGORY.Description

We need the value for (A) to be appropriately set.

Did you see the example that I included (http link), where they have the layout done similar to what we want, but when you click the "Edit" option in the example, the dropdowns all start with the item from index(0), rather than the value that matches what the current selection is.

Really, column (4) should display CATEGORY.Description, but be linked to value assigned to MAIN.CategoryID.

We could do this by having the CategoryID as a hidden column and looping through the grid to set the values to match and update the value with the dropdown.onchange(), but this seems like and awfully 'mickey mouse' way of doing things.

Hope this clarifies what we're trying to achieve here.

Regards,

Sean




Similar Threads
Thread Thread Starter Forum Replies Last Post
asp databound dropdownlist kent ASP.NET 1.0 and 1.1 Basics 7 June 2nd, 2008 09:07 AM
Getting a databound value from datalist contrrol almotions ASP.NET 2.0 Basics 8 April 23rd, 2008 09:00 AM
VS2005 DataGridViewComboBoxColumn databound CloudDust Visual Basic 2005 Basics 4 October 12th, 2006 06:29 PM
databound headertemplate collie VB.NET 2002/2003 Basics 0 March 7th, 2005 10:31 AM
Databound List Box Kunkel VS.NET 2002/2003 2 November 7th, 2003 01:38 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.