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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Binding Dictionary Object to a gridview

Status
Not open for further replies.

pinkpoppy

Programmer
Jul 6, 2011
75
0
0
US
I have a gridview that shows data. Data is called from a web service method.In one column, the values are displayed as abbreviation and I need those values displayed as the actual value. I have a Dictionary Object that I want to use to display the values.

Dictionary - where do I put this?
Code:
                Dictionary<string, string> dictionaryABC = new Dictionary<string, string>();
                dictionaryABC .Add("AA", "appples");
                dictionaryABC .Add("BB", "bananas");
                dictionaryABC .Add("CC", "corns");
                dictionaryABC .Add("DD", "daisies");
                dictionaryABC .Add("EE", "eggs");
                dictionaryABC .Add("FF", "fruits");
                dictionaryABC .Add("GG", "goats");

Code:
        private void GridView()
        {
            //data table
            DataTable dtGridView = new DataTable();

            string ID = "";

            if (ViewState["id"] != null)
            {
                ID = ViewState["id"].ToString();
            }

            //Call web service
            dtGridView = WebService.Method(ID);

            DataView dv = new DataView(dv);

            dv.Sort = "Year desc, Month desc";

            dtGridView = dtGridView .ToTable();

            if (dtGridView .Rows.Count > 0)
            {
                gridview.DataSource = dtGridView ;
                gridview.DataBind();
            }
            else
            {

                dtGridView .Rows.Add(dtGridView .NewRow());
                gridview.DataSource = dtGridView .DefaultView;
                gridview.DataBind();
            }
        }
 
I would convert the dictionary to a datatable.
Why do you have a dictionary object? In your last post, your webservice call returned a datatable. Just use that.
 
Can you show me an example? I am still working on this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top