Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 58001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:46:46+00:00 2026-05-10T17:46:46+00:00

What kind of collection I should use to convert NameValue collection to be bindable

  • 0

What kind of collection I should use to convert NameValue collection to be bindable to GridView? When doing directly it didn’t work.

Code in aspx.cs

  private void BindList(NameValueCollection nvpList)   {      resultGV.DataSource = list;      resultGV.DataBind();   } 

Code in aspx

<asp:GridView ID='resultGV' runat='server' AutoGenerateColumns='False' Width='100%'>     <Columns>          <asp:BoundField DataField='Key' HeaderText='Key' />          <asp:BoundField DataField='Value' HeaderText='Value' />     </Columns> </asp:GridView> 

Any tip most welcome. Thanks. X.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T17:46:46+00:00Added an answer on May 10, 2026 at 5:46 pm

    Can you use Dictionary<string,string> instead of NameValueCollection. Since Dictionary<T,T> implements IEnumerable you could use LINQ as so:

    resultGV.DataSource = from item in nvpDictionary                       select new { Key = item.Key, Value = item.Value }; resultGV.DataBind(); 

    [EDIT] Actually you may be able to use Dictionary directly as:

    resultGV.DataSource = nvpDictionary; resultGV.DataBind(); 

    If it doesn’t map key/value the way you want you can always go back to LINQ. LINQ would also allow you to rename the fields to whatever you want.

    [EDIT] If you can’t change to use Dictionary<T,T>, make a copy of the NameValueCollection as a Dictionary in the method and bind to it.

    private void BindList(NameValueCollection nvpList) {    Dictionary<string,string> temp = new Dictionary<string,string>();    foreach (string key in nvpList)    {       temp.Add(key,nvpList[key]);    }     resultGV.DataSource = temp;    resultGV.DataBind(); } 

    If you do this a lot, you could write an extension method to convert to a Dictionary, and use it so.

    public static class NameValueCollectionExtensions {    public static Dictionary<string,string> ToDictionary( this NameValueCollection collection )    {       Dictionary<string,string> temp = new Dictionary<string,string>();       foreach (string key in collection)       {           temp.Add(key,collection[key]);       }       return temp;    } }  private void BindList(NameValueCollection nvpList) {    resultGV.DataSource = nvpList.ToDictionary();    resultGV.DataBind(); } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What kind of collection should I use if I need to create a collection
What kind of DB should I use for a node.js server that needs to
I have two classes, but don't what kind of relation i should use. I
Should I use old synchronized Vector collection, ArrayList with synchronized access or Collections.synchronizedList or
In most of the methods I use that return some kind of collection I
Suppose I have a Collection of some kind that itself contains Collections; e.g., Dictionary(Of
I'm using this kind of code for my TCP/IP connection: sock = new Socket(host,
Kind of like this question I have many text snippets that I use many,
Kind of need help understanding what this code actually outputs. Does it out put
Which storage method should I use when using ASP.NET Charting Tools? I'm currently using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.