Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rename values in dataset

Status
Not open for further replies.

pinkpoppy

Programmer
Jul 6, 2011
75
US
I have a dataset that calls the values from the webservice. In the datasets are abbreivated values (e.g., AA, BB, CC, DD) and I need to display the values on my dropdownlist as its whole names such as AA = APPLE, BB = BEES. Here's is an example of my method.

How can I rename the values in the dataset to what I want?

Code:
DataTable dtEntryInfo = new DataTable();
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                DropDownList ddlABC = (DropDownList)e.Row.FindControl("ddlABC");
                DataSet dsABCInfo = new DataSet();

                if (ViewState["id"] != null)
                {
                    // call the web service
                    dsABCInfo = WEBService.ABCDEF((ViewState["ABC"].ToString()));

                    int cInx = 0;
                    ddlABC .Items.Clear();
                    ddlABC .Items.Add(new ListItem("Select", ""));

                    if (dsABCInfo .Tables["dtABC"].Rows.Count > 0)
                    {
                        while (cInx <= dsABCInfo .Tables["dtABC"].Rows.Count - 1)
                        {
                            ddlABC .Items.Add(new ListItem(dsABCInfo .Tables["dtABC"].Rows[cInx]["Court"].ToString(),
                                dsABCInfo .Tables["dtABC"].Rows[cInx]["Court"].ToString()));


                            cInx = cInx + 1;
                        }
                    }
 
Can you change the webservice to send back the actual values you need?
if not, you will have to loop through the datatable and change each value.
 
Thanks for the reply. We prefer to to change the values in the code rather than the web service. it is much more flexible. Can you show me an example?
 
Code:
foreach (DataRow dr in yourDataTable.Rows)
   {
      dr["columnToChange"] = "valueToChangeTo";    
   }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top