Bind NameValueCollection to a DataGrid

  • Thread starter Thread starter Hardy Wang
  • Start date Start date
H

Hardy Wang

Hi,
I have a NameValueCollection, is it possible to bind this object to a
two-column DataGrid? How to match columns?

Thanks!
 
It seems that it doesn't work:
<asp:DataGrid id="dgServerVariables" runat="server"
AutoGenerateColumns="False">
<AlternatingItemStyle BackColor="#F7F7F7"></AlternatingItemStyle>
<ItemStyle ForeColor="#4A3C8C" BackColor="#E7E7FF"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#F7F7F7"
BackColor="#4A3C8C"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="Key" HeaderText="Key"></asp:BoundColumn>
<asp:BoundColumn DataField="Value" HeaderText="Value"></asp:BoundColumn>
</Columns>
</asp:DataGrid>

In code behind:
private void loadServerVariables() {
NameValueCollection coll;

// Load ServerVariable collection into NameValueCollection object.
coll = Request.ServerVariables;

dgServerVariables.DataSource = coll;
dgServerVariables.DataBind();
}

Then I get error:
A field or property with the name 'Key' was not found on the selected
datasource.
 
SortedList or classes derived from DictionaryBase should do.

Eliyahu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top