我正在尝试解决我的下拉菜单的问题,所以我尝试使用属性在页面上修复它但是当我读取selectedindexchanged中的值时。
public Guid _appointmentType { get; set; }
protected void Page_Init(object sender,EventArgs e)
{
string id = Request.QueryString["id"];
Guid _guid = string.IsNullOrEmpty(id) ? new Guid() : new Guid(id);
_shifts = _dal.GetShiftPatternById(_guid);
if (!IsPostBack)
{
var dlManagersSource = _dal.GetManagers();
rdManagers.DataSource = dlManagersSource;
rdManagers.DataValueField = "LookupValue";
rdManagers.DataTextField = "LookupDescription";
rdManagers.DataBind();
var ddlShiftPatterns = _dal.GetShiftPatternTypes();
rdAppointmentType.DataSource = ddlShiftPatterns;
rdAppointmentType.DataValueField = "LookupValue";
rdAppointmentType.DataTextField = "LookupDescription";
rdAppointmentType.DataBind();
}
rdDayOfWeek.SelectedValue = _shifts.dayOfWeek.ToString();
rdManagers.SelectedValue = _shifts.manager_Id.ToString();
txtDescription.Text = _shifts.Description;
rdStartShift.SelectedDate = _shifts.startdate;
rdShiftEnd.SelectedDate = _shifts.endDate;
}
protected void rdAppointmentType_SelectedIndexChanged(object sender, DropDownListEventArgs e)
{
_appointmentType = new Guid(rdAppointmentType.SelectedValue);
}
但是当我重新加载记录时,它已将其保存为null而不是obv的值我有一个保存实体的保存事件但我的问题是我不认为我使用的方法来匹配guid要观看已经在下拉状态,因为它停留在第一个迭代请选择。
<div class="form-group">
<label class="col-md-4 control-label" for="val_bio">Appointment Type<span class="text-danger">*</span></label>
<div class="input-group col-md-7">
<telerik:RadDropDownList ID="rdAppointmentType" OnSelectedIndexChanged="rdAppointmentType_SelectedIndexChanged" DefaultMessage="Please Select" runat="server" Skin="Bootstrap"></telerik:RadDropDownList>
</div>
</div>
我认为我的主要问题是这一行
rdManagers.SelectedValue = _shifts.manager_Id.ToString();
答案 0 :(得分:0)
您在_appointmentType
上丢失了属性PostBack
的内容。您可以在ViewState
而不是:
public Guid _appointmentType { get; set; }
使用像这样的属性
private Guid _appointmentType
{
get
{
if (ViewState["_appointmentType"] == null)
{
return null;
}
return (Guid)ViewState["_appointmentType"];
}
set
{
ViewState["_appointmentType"] = value;
}
}