如题我在DropDownList绑定了datasource,且DropDownList能从数据库取出数据.需求:在页面加载的时候(Page_load)事件中怎么获取DropDownList的默认值呢?
DropDownList的Selected...属性都不能获取得到..
是不是我的思路有问题?有没有更好的思路...
请教
DropDownList的Selected...属性都不能获取得到..
是不是我的思路有问题?有没有更好的思路...
请教
确定你的datasource 有数据 ?
不过,可以手动的绑定一下datasource 就能获得ddl.SelectedValue了...
呵呵.....
DataSourceID="SqlDataSourceRoom" DataTextField="RoomId" DataValueField="RoomId">
<asp:ListItem Selected="True" Value="-1">--请选择科室--</asp:ListItem>
</asp:DropDownList>
通过dropdownlist动态绑定gridview某一列的不同效果,比方说:dropdownlist通过datasource绑定学员的学号.现在是通过dropdownlist的SelectedIndexChanged事件把该学员的成绩显示在gridview的某一列.已经实现,但是在页面第一次加载的时候,没有(SelectedIndexChanged)事件.当然gridview就没有自然也没有成绩列显示..(即使默认第一个学员有成绩,也没有成绩显示出来),需求是第一次加载的时候.(gridview)也能显示第一个学员学号的成绩..
<tr>
<td width="120" align="right">案例类型</td>
<td>
<asp:DropDownList ID="ddlTypes" runat="server"></asp:DropDownList>
<asp:Literal ID="lal" runat="server"></asp:Literal></td>
<td width="464"> </td>
</tr>protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ShowAllTypes();
int i = 0;
if (int.TryParse(Request.QueryString["pid"], out i))
{
if (i > 0)//修改
{
ShowProInfoByEID(i);
}
}
}protected void ShowAllTypes()
{
this.ddlTypes.DataSource = DAL.AccessService.TypesService.GetAllTypes();//数据库读取
ddlTypes.DataTextField = "TP_Name";
ddlTypes.DataValueField = "TPID";
this.ddlTypes.DataBind();
}
/// <summary>
/// 载入图片:在编辑更新案例时执行该方法
/// </summary>
/// <param name="id"></param>
protected void ShowProInfoByEID(int id)
{
Projcets pro = ProjectsService.GetProByPIDToProDetail(id);
if (pro != null)
{
this.proImg.Src = "../../proImgs/" + pro.P_Pic;//注意路径
this.subProImg.Src = "../../proImgs/" + pro.P_SPic;
this.HidProPic.Value = pro.P_Pic;//临时保存图片名称,可用于图片没有发生改变时候用
this.HidProSubPic.Value = pro.P_SPic;
//this.ddlTypes.SelectedItem.Text = pro.P_Type.TP_Name;
this.txtSum.Text = pro.P_Summary;
this.txtProTitle.Text = pro.P_Title;
ddlTypes.SelectedItem.Value = pro.P_Type.TPID.ToString();//楼主的问题
ddlTypes.SelectedItem.Text = pro.P_Type.TP_Name; }
}