0
所以我有這些dropdownlists,我需要更新時,用戶更改它的價值。問題是無論我嘗試多少值,價值都是一樣的。問題是什麼?asp淨下拉selectedvalue/selectedindex不在中繼器更新
ASPX:
<asp:Repeater runat="server" OnItemCommand="rptList_OnItemCommand" ID="rptList">
<td>
<ItemTemplate>
<asp:LinkButton CommandName="selectBtn" ToolTip="TRNSLTEdit" ID="btnEdit" CssClass="editOperator" runat="server" CommandArgument='<%# Eval("ID")%>' OnClientClick="return PopupEdit(this)">
<asp:Image ImageUrl="Images/Icons/Edit-16x16.png" ID="EditVisitor" runat="server" />
</asp:LinkButton>
<div id="modalEdit" class="modal">
<div class="modal-content">
<p style="margin-left: 50px;">
<img src="Images/Icons/Sip.png" alt="" />
<%# Eval("FirstName") %> <%# Eval("SurName") %>
</p>
<br />
<asp:DropDownList CssClass="ddlNodeClass" runat="server" ID="ddlNodeEdit" />
<asp:DropDownList CssClass="ddlTranslatorClass" runat="server" ID="ddlTranslatorEdit" />
<asp:LinkButton ToolTip="TRNSLTCancel" CommandArgument='<%# Eval("ID") %>' ID="btnNo" runat="server" CssClass="btnCancelClass" OnClientClick="return Cancel(this)">
<asp:Image ImageUrl="Images/Icons/Cancel-22x22.png" ID="SaveContact" runat="server" ClientIDMode="Static" />
</asp:LinkButton>
<asp:LinkButton ToolTip="TRNSLTSave" CommandName="submitBtn" CommandArgument='<%# Eval("ID") %>' ID="btnYes" runat="server" CssClass="btnSaveClass">
<asp:Image ImageUrl="Images/Icons/Check-22x22.png" ID="SaveOperator" runat="server" ClientIDMode="Static" />
</asp:LinkButton>
</div>
</div>
</td>
</ItemTemplate>
</asp:Repeater>
C#(aspx.cs):
protected void Page_Load(object sender, EventArgs e)
{
RptDataBind();
}
/// <summary>
/// Assigning commands to listing repeater.
/// </summary>
protected void rptList_OnItemCommand(object source, RepeaterCommandEventArgs e)
{
var tellusUserId = TellusUser.UserID;
var operatorId = Convert.ToInt64(e.CommandArgument);
switch (e.CommandName)
{
case "submitBtn":
var ddlNodeEdit = (DropDownList)e.Item.FindControl("ddlNodeEdit");
var ddlTranslatorEdit = (DropDownList)e.Item.FindControl("ddlTranslatorEdit");
ViewState["NodeIndex"] = ddlNodeEdit.SelectedIndex; //Still old value
ViewState["TranslatorValue"] = ddlTranslatorEdit.SelectedValue; //Still old value
_administrationSystem.UpdateOperator(tellusUserId, operatorId, TellusUser.UserID, Convert.ToInt32(ViewState["NodeIndex"]), Convert.ToInt64(ViewState["TranslatorValue"]), "");
ViewState["ID"] = operatorId;
break;
}
}
/// <summary>
/// Sets datasource and databind to aspx page.
/// </summary>
public void RptDataBind()
{
var userId = TellusUser.UserID;
_administrationSystem = new Administration();
_phonesSystem = new Phones();
var operatorInfo = _administrationSystem.GetOperatorsInformation(userId);
rptList.DataSource = operatorInfo;
rptList.DataBind();
if (rptList.Items.Count > 0)
{
for (var count = 0; count < rptList.Items.Count; count++)
{
var ddlNodeEdit = (DropDownList)rptList.Items[count].FindControl("ddlNodeEdit");
var ddlTranslatorEdit = (DropDownList)rptList.Items[count].FindControl("ddlTranslatorEdit");
var getNode = _administrationSystem.GetNode(userId, ddlNodeEdit.SelectedIndex + 1); //DataSet from DB
var getTranslator = _phonesSystem.GetPhoneNumberTranslator(ddlTranslatorEdit.SelectedIndex); //DataSet from DB
ddlNodeEdit.DataSource = getNode;
ddlNodeEdit.DataTextField = "NodeName";
ddlNodeEdit.DataValueField = "ID";
ddlTranslatorEdit.DataSource = getTranslator;
ddlTranslatorEdit.DataTextField = "Description";
ddlTranslatorEdit.DataValueField = "ID";
ddlNodeEdit.DataBind();
ddlTranslatorEdit.DataBind();
ViewState["NodeIndex"] = ddlNodeEdit.SelectedIndex;
ViewState["TranslatorValue"] = ddlTranslatorEdit.SelectedValue;
}
}
}
所以,出於某種原因。下拉列表selectedvalue和selectedindex是相同的,即使我在調試時更改爲另一個值,有沒有人有任何建議?
確定這有效,但是當我更新聯繫人時,只有一個用戶得到更新,同一個用戶,不管我選擇誰。爲什麼? – Malphai
@Malphai - 我不確定你如何更新聯繫人,你有沒有調試代碼,看看發生了什麼?這是解決問題的最佳方式。如果你堅持讓我知道。 –
我得到的id是正確的(通過我的命令參數),但由於某種原因,它在以後再次更新相同的聯繫人時會返回到rptdatabind? – Malphai