databind to datarow

M

Maziar Aflatoun

Hi,

I have a DataRow that I want to bind to a dropdown list. I have 2 columns
(TypeName, TypeValue). When do

ddlNewAttribute.DataSource = drAttrValues;
ddlNewAttribute.DataBind();

How do I go about binding to a specific column (TypeValue)?

Right now I'm getting [System.Data.DataRow] for the values.

Thanks
Maz.
 
A

Andrea Zani

Maziar Aflatoun said:
Hi,

I have a DataRow that I want to bind to a dropdown list. I have 2
columns (TypeName, TypeValue). When do

ddlNewAttribute.DataSource = drAttrValues;
ddlNewAttribute.DataBind();

How do I go about binding to a specific column (TypeValue)?

Right now I'm getting [System.Data.DataRow] for the values.

Thanks
Maz.

ddlNewAttribute.DataTextValue="TypeName"
ddlNewAttribute.DataFieldValue="TypeValue"
ddlNewAttribute.DataSource = drAttrValues;
ddlNewAttribute.DataBind();
 
S

Sam Samnah

Remember DropDownList fills listItems with the datasource when bound.
So what you can do is for instance:

ddlNewAttribute.datasource=DataSet;
ddlNewAttribute.datamember="tableReferance"
ddlNewAttribute.DataBind();
// Selects the row and adds it to ListItem collection
ddlNewAttribute.Items.Add(new ListItem("TypeName, "TypeValue"));
// To set the index of the Item use the insert method.
ddlNewAttribute.Items.insert(int index, new
ListItem("TypeName","TypeValue"));
/*If your trying to bind the DropDownList to a templated control, rather in
the EditItemTemplate, the DropDownList does not exist until the user selects
edit so the binding process is different. You'll have to create a method
that calls the data in the codebehind and and stuff it (I prefer DataView
object) into an object and set the datasource at runtime.
I'd show you but I'm to lazy right now :). */

I am Sam-
 
S

Sam Samnah

Remember DropDownList fills listItems with the datasource when bound.
So what you can do is for instance:

ddlNewAttribute.datasource=DataSet;
ddlNewAttribute.datamember="tableReferance"
ddlNewAttribute.DataBind();
// Selects the row and adds it to ListItem collection
ddlNewAttribute.Items.Add(new ListItem("TypeName, "TypeValue"));
// To set the index of the Item use the insert method.
ddlNewAttribute.Items.insert(int index, new
ListItem("TypeName","TypeValue"));
/*If your trying to bind the DropDownList to a templated control, rather in
the EditItemTemplate, the DropDownList does not exist until the user selects
edit so the binding process is different. You'll have to create a method
that calls the data in the codebehind and and stuff it (I prefer DataView
object) into an object and set the datasource at runtime.
I'd show you but I'm to lazy right now :). */

I am Sam-
 
S

Sam Samnah

Remember DropDownList fills listItems with the datasource when bound.
So what you can do is for instance:

ddlNewAttribute.datasource=DataSet;
ddlNewAttribute.datamember="tableReferance"
ddlNewAttribute.DataBind();
// Selects the row and adds it to ListItem collection
ddlNewAttribute.Items.Add(new ListItem("TypeName, "TypeValue"));
// To set the index of the Item use the insert method.
ddlNewAttribute.Items.insert(int index, new
ListItem("TypeName","TypeValue"));
/*If your trying to bind the DropDownList to a templated control, rather in
the EditItemTemplate, the DropDownList does not exist until the user selects
edit so the binding process is different. You'll have to create a method
that calls the data in the codebehind and and stuff it (I prefer DataView
object) into an object and set the datasource at runtime.
I'd show you but I'm to lazy right now :). */

I am Sam-
 

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

Top