Hi there...
At the page where your GridView and DropDownList in it exists....
... I suppose your GridView Id is
gdvUser and DropDownList id is
drpUser... put these line to set index... and you're binding only one record to the GridView...
DropDownList drpL = (DropDownList) gdvUser.Rows[0].FindControl("drpUser");
drpL.SelectedIndex = 0;
In above code, I supposed you're filling only one record so I targeted Row at position 0 in GridView. You can target any row as per your requirement. In case you want to set DropDownList index for all records in GridView, you can use for loop...
for(int i=0;i<gdvUser.Rows.Count;i++)
{
DropDownList drpL = (DropDownList) gdvUser.Rows[i].FindControl("drpUser");
drpL.SelectedIndex = 0;
}
Also you can find an Item of dropdown list using Text or Value properties of item.
Examples:
DropDownList drpL = (DropDownList) gdvUser.Rows[0].FindControl("drpUser");
drpL.clearSelection();
drpL.Items.FindByText("SomeText").Selected = true;
DropDownList drpL = (DropDownList) gdvUser.Rows[0].FindControl("drpUser");
drpL.clearSelection();
drpL.Items.FindByValue("SomeValue").Selected = true;
DropDownList drpL = (DropDownList) gdvUser.Rows[0].FindControl("drpUser");
ListItem li = new ListItem("SomeText","SomeValue");
drpL.clearSelection();
drpL.Items[li].Selected = true;
Note: In above three examples it's important to clear the selection before programmatically selecting a new item, otherwise an error will be shown about no more than a ListItem can be selected at a time.
I hope you got the solution of your query. Good Luck! :)