Welcome to Dream.In.Code
Become an Expert!

Join 150,045 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,630 people online right now. Registration is fast and FREE... Join Now!




Wrong output on radioButtonList

 
Reply to this topicStart new topic

Wrong output on radioButtonList, binding to the wrong info..?

Footsie
12 Feb, 2008 - 03:02 AM
Post #1

D.I.C Regular
Group Icon

Joined: 20 Sep, 2007
Posts: 308



Thanked: 4 times
Dream Kudos: 50
My Contributions
I want to fill a radioButtonList control with the result of a SELECT statement from another radioButtonList control.

Here is the code: (my error follows)
CODE
  
protected void radioListManufacturers_SelectedIndexChanged(object sender, EventArgs e)
    {
        
        //get the manufacturer that the user selected
        string manufSelect = radioListManufacturers.SelectedValue.ToString();
        Label1.Text = manufSelect;

        //Run a SELECT statement to get all the model names,
        //that match the manufacturer selected

        MySqlConnection conn = new MySqlConnection(DataAccessClass.GetConnectionString("AFPConnection"));
        
        MySqlCommand com = conn.CreateCommand();
        
        com.CommandType = CommandType.Text;
        com.CommandText = "SELECT DISTINCT modelname FROM basevehicle WHERE(manufacturer = ?vManu)";
        com.Parameters.Add
("?vManu", MySqlDbType.VarChar).Value = manufSelect;
        
        //create dataset
        DataSet dsModels = new DataSet();

        //dataAdapter
        MySqlDataAdapter adapter = new MySqlDataAdapter();
        adapter.SelectCommand = com;
        
        //fill dataset
        adapter.Fill(dsModels);

        //tell radiobuttonlist where the info is and bind it
        radioListModels.DataSource = dsModels;
        radioListModels.DataBind();

        //tell the gridview where the info is and bind it
        GridView1.DataSource = dsModels;
        GridView1.DataBind();
      }


In the preceding code my GridView1 presents the correct info eg:
CODE

modelname
--------------
Rodeo


but the radioList presents this info System.Data.DataRowView
So it seems to work but I get the wrong info for the radioList.
It should present "Rodeo".
I think I'm binding to the wrong info..?

How can I rectify this? Any help would be great.
Thanks!




User is offlineProfile CardPM
+Quote Post

Footsie
RE: Wrong Output On RadioButtonList
12 Feb, 2008 - 12:50 PM
Post #2

D.I.C Regular
Group Icon

Joined: 20 Sep, 2007
Posts: 308



Thanked: 4 times
Dream Kudos: 50
My Contributions
Ok, I've worked this out. icon_up.gif
But I have just another general question. (below)
This is what I added:
CODE


      //fill dataset and give it the name of the table
        adapter.Fill(dsModels,"modelname");

      //tell radiobuttonlist where the info is and bind it
        radioListModels.DataSource = dsModels.Tables[0];
        
       //tell it where to get the text field you want
        radioListModels.DataTextField = "modelname";
        radioListModels.DataValueField = "modelname";

        radioListModels.DataBind();

Ok this works so far. What I want to know though is this: If I comment out the line with DataTextField in and run it it works and likewise DataValueField.
Do I have to assign both of them? Or just one?
Thanks.

EDIT: added the line radioListModels.DataSource = dsModels.Tables[0];

This post has been edited by Footsie: 12 Feb, 2008 - 01:06 PM
User is offlineProfile CardPM
+Quote Post

dygytalnomad
RE: Wrong Output On RadioButtonList
12 Feb, 2008 - 01:00 PM
Post #3

New D.I.C Head
*

Joined: 12 Feb, 2008
Posts: 6


My Contributions
QUOTE(Footsie @ 12 Feb, 2008 - 01:50 PM) *

Ok, I've worked this out. icon_up.gif
But I have just another general question. (below)
This is what I added:
CODE


      //fill dataset and give it the name of the table
        adapter.Fill(dsModels,"modelname");

      //tell radiobuttonlist where the info is and bind it
        radioListModels.DataSource = dsModels;
        
       //tell it where to get the text field you want
        radioListModels.DataTextField = "modelname";
        radioListModels.DataValueField = "modelname";

        radioListModels.DataBind();

Ok this works so far. What I want to know though is this: If I comment out the line with DataTextField in and run it it works and likewise DataValueField.
Do I have to assign both of them? Or just one?
Thanks.



You need the Value field if you need the value later to insert or update a database. The text field is used more or less to display the information to the user. The value field is usually a key value for the database.

HTH
User is offlineProfile CardPM
+Quote Post

Footsie
RE: Wrong Output On RadioButtonList
13 Feb, 2008 - 05:27 AM
Post #4

D.I.C Regular
Group Icon

Joined: 20 Sep, 2007
Posts: 308



Thanked: 4 times
Dream Kudos: 50
My Contributions
Ok, so would it be better to name them something different then? Are there any conventions for naming them?

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 10:00PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month