databind to datarow

  • Thread starter Thread starter Maziar Aflatoun
  • Start date Start date
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.
 
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();
 
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-
 
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-
 
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-
 
Back
Top