Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have written the following code to get value in a dropdownlist and a textbox. The dropdownlist is "ddlSpareParts" and the textbox is "txtSPMCode" . I run a loop to get the value of gridview "grdEditSparePartsMaintenance" and show the result in ddlSpareParts and txtSPMCode . But I get value in textbox but don't get value in dropdownlist. Please solve the problem and help me.
C#
ddlSpareParts.Text = grdEditSparePartsMaintenance.Rows[k].Cells[2].Text.Trim();
txtSPMCode.Text = grdEditSparePartsMaintenance.Rows[k].Cells[4].Text;
Posted
v2

Add values in drop down like
C#
ddlSpareParts.Items.Add(grdEditSparePartMaintenance.Rows[k].Cells[2].Text.Trim());
 
Share this answer
 
v2
Hello Prince,

To read the value from DropDownList you first need to get a handle on the control. Use code similar to one shown below to retrieve a reference to DropDownList. Then you can read the value.
VB
Dim ctrl As Control
Dim row As GridViewRow
Dim ddl as DropDownList 

row = grdEditSparePartsMaintenance.Rows[k]
ctrl = row.FindControl("ddlSpareParts")
ddl = TryCast(ctrl, DropDownList)
txtSPMCode.Text = ddl.SelectedValue

Regards,
 
Share this answer
 
You have to add the values in the dropdown.
For e.g. try ddlSparePart.Items.Add(grdEditSparePartsMaintenance.Rows[k].Cells[2].Text.Trim().
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900