隐藏字段中的相同值以及后续回发

时间:2017-04-19 08:02:45

标签: c# dropdown hidden-field

我在内容占位符中有一个隐藏字段(hdn_vill),只有在回发发生时才会初始化但是每次下拉选择更改后的事件都会在hdn_vill中用逗号分隔连接相同的值(例如:“ 2,2,2,2,2“)

页面加载事件

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            try
            {
                if (Request.QueryString["vill"] != null)
                    hdn_vill.Value = (Microsoft.Security.Application.Encoder.HtmlEncode(CommonFunction.TripleDESDecrypt(Request.QueryString["vill"].ToString())).ToString());
            }
            catch (Exception ex)
            {
            }
        }
    }

以下是选择事件更改事件

protected void ddl_Igrs_khata_SelectedIndexChanged(object sender, EventArgs e)
{
    if (ddl_Igrs_khata.SelectedIndex > 0)
    {

            FillOwnerDetail(ddl_Igrs_owner, 0,Convert.ToInt32(Encoder.HtmlEncode(hdn_vill.Value)));

        }

    }

HiddenField Control

<asp:HiddenField ID="hdn_vill" runat="server" Value="" />

下拉控件

<asp:DropDownList ID="ddl_Igrs_khata" runat="server" Width="100px" Font-Size="16px"
                            ForeColor="Black" Visible="false" class="" OnSelectedIndexChanged="ddl_Igrs_khata_SelectedIndexChanged"
                            Height="30px" AutoPostBack="True">
                        </asp:DropDownList>

填写所有者详细信息功能

protected void FillOwnerDetail(DropDownList ddl, int flag, string khatano)
    {
        try
        {
            LRCBl objlrcbl = new LRCBl();
            Checks ch = new Checks();
            int count = 0;

            if (!ch.IsValidNum(hdn_vill.Value) && !ch.IsValidNum(hdn_areaunit.Value))
            {
                //DataTable dt = objlrcbl.Usp_Ownership_wise_mutation("Get_owner_Detail_IGRSRahan_Khata", Convert.ToString(Encoder.HtmlEncode(hdn_vill.Value)), "", khatano, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "");
                DataTable dt = objlrcbl.IGRS_RahanamaMut("", 9, Convert.ToInt32(Encoder.HtmlEncode(hdn_vill.Value)), khatano, 0, "", 0, regno);
                if (dt.Rows.Count > 0)
                {
                    ddl.DataSource = dt;
                    ddl.DataTextField = "oname";
                    ddl.DataValueField = "unique_id";
                    ddl.DataBind();
                    count++;
                }
                if (count > 0 && count < 2)
                {
                    ddl_Igrs_owner.Items.Insert(0, new ListItem("चुने", "0"));
                }

            }

        }

1 个答案:

答案 0 :(得分:1)

您的客户端代码应如下所示:

<asp:HiddenField runat="server" ID="hdn_vill" />
<asp:DropDownList runat="server" ID="dropDownList" AutoPostBack="true" OnSelectedIndexChanged="dropDownList_SelectedIndexChanged">
/* Populate the control */
</asp:DropDownList>

虽然您的服务器代码应如下所示:

protected void dropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
    hdn_vill.Value = string.Format("{0}{1},", hdn_vill.Value, dropDownList.SelectedValue);
}

这很简单,如果没有看到你的代码并知道问题是什么,就能做得更好。