i have a dropdownlist in a gridview
<asp:TemplateField HeaderText="Backup Frequency">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Text="Once a Day" Value="86400">Once a Day</asp:ListItem>
<asp:ListItem Text="Once a weak" Value="604800">Once a week</asp:ListItem>
<asp:ListItem Text="As They Change" Value="0">As They Change</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
now it displays Once a Day in the dropdownlist in each row…. but i want that the first row should have its dropdownlist showing “As They Change”…
protected void GridView1_DataBound(object sender, EventArgs e)
{
foreach (GridViewRow myRow in GridView1.Rows)
{
Label Label1 = (Label)myRow.FindControl("Label1");
if (Label1.Text == "User Data")
{DropDownList DropDownList1 = (DropDownList)myRow.FindControl("DropDownList1");
DropDownList1.SelectedValue = "As They Change";
}
}
}
but this is not showing As they change…
Any suggestions??
You’re setting SelectedValue but your DropDownList Values are “84600”, “604800”, “0”. You need to set the SelectedValue to “0” for “As they change” to show.