初学都问题?DropDownList如何默认值??
在GridView里加入DropDownList,数据从库中邦定,编辑时如何设置默认值??
下面是我在后台的设置,但不对啊ropDownList不能默认!!!还有顺便请教下如果是删除,如果删除为管理员自己行,那么GridView中的删除按扭不可用如何设置??
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
Label user = (Label)e.Row.FindControl( "Name ");
if (user.Text == Request.Cookies[ "name "].Value)
{
LinkButton Del = (LinkButton)e.Row.FindControl( "LinkButton2 ");
Del.Enabled = false;
}
DropDownList RoleId = (DropDownList)e.Row.FindControl( "RoleId ");
OleDbDataReader DataReader = DataOption.GetDataRead( "select Rid from Role where Rname= ' " + Request.Cookies[ "Rname "].Value + " ' ");
RoleId.SelectedValue = Request.Cookies[ "Rname "].Value;
//RoleId.SelectedIndex = Convert.ToInt32(DataReader[ "Rid "]);
}
前台 DropDownList
<asp:TemplateField HeaderText= "角色 ">
<EditItemTemplate>
<asp:DropDownList ID= "RoleId " runat= "server " DataSource= " <%#RoleDownList()%> "
DataTextField= "Rname " DataValueField = "Rid ">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID= "lblRoleId " runat= "server " Text= ' <%# Eval( "Rname ") %> '> </asp:Label>
</ItemTemplate>
</asp:TemplateField>