Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
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
Reply With Quote
  #2 (permalink)  
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();
        }
Reply With Quote
  #3 (permalink)  
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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 09:31 AM
Databound List Box Kunkel VS.NET 2002/2003 2 November 7th, 2003 12:38 PM



All times are GMT -4. The time now is 12:39 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.