|
Have a datagrid,
One of the columns:
<asp: TemplateColumn HeaderText = "Business Class">
<HeaderStyle Width = "40px"> </ HeaderStyle>
<ItemTemplate>
<% # DataBinder.Eval (Container.DataItem, "ywdesp")%>
</ ItemTemplate>
<EditItemTemplate>
<asp: dropdownlist ID = "yk" runat = "server">
<asp: listitem Value = "0" Text = "Other" />
<asp: listitem Value = "1" Text = "内 一" />
<asp: listitem Value = "2" Text = "内 二" />
<asp: listitem Value = "3" Text = "Export" />
<asp: listitem Value = "4" Text = "marketing" />
</ asp: dropdownlist>
</ EditItemTemplate>
</ asp: TemplateColumn>
In the non-editing state, "Other", "Inner one", "Inner two", "Export", "Marketing" and the like are displayed, but I want to yk (DropDownList) when in the "Edit" state SelectedIndex = 0, "Internal one" SelectedIndex = 1, ...
But I use the following code, the operation is not successful, please help, thank you!
public void gridUserItemDataBound (object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType! = ListItemType.Header)
{
switch (e.Item.Cells [3] .Text)
{
case "Other":
deptIndex = 0;
break;
case "内 一":
deptIndex = 1;
break;
case "内 二":
deptIndex = 2;
break;
case "Export":
deptIndex = 3;
break;
case "Marketing":
deptIndex = 4;
break;
}
Ranch
if (e.Item.ItemType == ListItemType.EditItem)
{
DropDownList myddl = (DropDownList) e.Item.FindControl ("yk");
myddl.SelectedIndex = deptIndex;
}
}
} |
|