Question : VB ItemData property in .net

How do we get the itemdata property we use in the VB's combo box or the list box with in the .Net. I have a dropdownlist on my aspx form and I'm doing the follwoing to populate it.

ddlRequisition.DataSource = requisitionType.GetRequisitionTypes();
ddlRequisition.DataBind();

This GetRequisitionType is a datareader and got name and ID fileds. What should happen here is when the user select the name and I wanted to take the corresponding id filed and populate the textbox with that value. Like:

protected void ddlRequisition_SelectedIndexChanged(object sender, EventArgs e)
        {            
            txtGlCode.Text = ddlRequisition.Items[1].Value;
        }
But when I changed the selection in the ddlRequisition nothing is changing in the text box even though that event was fired. Is that something we need to do here, like the itemdata property we do in VB? if so how?

Answer : VB ItemData property in .net

1: make sure you are databinding on first time pageload only i.e.
2: set the DataText and DataField value of your DDL

if(!Page.IsPostBack)
{
ddlRequisition.DataSource = requisitionType.GetRequisitionTypes();
ddlRequisition.DataTextField = "YourNameField";
ddlRequisition.DataValueField = "YourIDField";
ddlRequisition.DataBind();
}

Random Solutions  
 
programming4us programming4us