首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用java脚本设置CascadingDropDown值

如何使用java脚本设置CascadingDropDown值
EN

Stack Overflow用户
提问于 2012-06-27 13:02:19
回答 1查看 1.2K关注 0票数 0

我有两个级联下降和一个网格视图控制。在页面加载iam绑定网格视图上,当我单击特定行iam试图填充Rowcommand事件中的级联下拉列表时。aspx代码

代码语言:javascript
复制
<asp:DropDownList ID="txttechnology" runat="server" ClientIDMode="Static" Font-Size="8pt"
                        Width="155px" TabIndex="7">
                    </asp:DropDownList>
                    <asp:CascadingDropDown ID="CascadingDropDown1" runat="server" TargetControlID="txttechnology" ClientIDMode="Static"
                        Category="Make" PromptText="Select Technology" ServicePath="~/google.asmx" ServiceMethod="GetTechnology" SelectedValue=""/>

<asp:DropDownList ID="txtprimaryskills" runat="server" ClientIDMode="Static" Font-Size="8pt"
                        Width="155px" TabIndex="8">
                    </asp:DropDownList>
                    <asp:CascadingDropDown ID="CascadingDropDown2" runat="server" TargetControlID="txtprimaryskills" ClientIDMode="Static"
                        ParentControlID="txttechnology" PromptText="Select Skill" ServiceMethod="GetSkill"
                        ServicePath="~/google.asmx" Category="Model" SelectedValue="" />

行命令事件代码

代码语言:javascript
复制
int type = convert.toint32(e.commandargument.tostring());
 cascadingdropdown1.selectedvalue =grdindirectconsultant.rows[type].cells[2].text.tostring().trim();
cascadingdropdown2.selectedvalue = grdindirectconsultant.rows[type].cells[3].text.tostring().trim();

web服务方法

代码语言:javascript
复制
 [WebMethod]
    public CascadingDropDownNameValue[] GetTechnology(string knownCategoryValues,string category)
    {
        List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
        try
        {           
            DataSet makes = SqlHelper.ExecuteDataset(LITRMSConnection, "usp_getskills");
            for (int i = 0; i < makes.Tables[0].Rows.Count; i++)
            {
                string make = makes.Tables[0].Rows[i]["Technology"].ToString();
                string makeId = makes.Tables[0].Rows[i]["ID"].ToString();
                values.Add(new CascadingDropDownNameValue(make, makeId));
            }
        }
        catch (Exception ex)
        {

        }
        return values.ToArray();
    }
    [WebMethod]
      public CascadingDropDownNameValue[] GetSkill(string knownCategoryValues, string category)
      {
          List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
          try
          {
              System.Collections.Specialized.StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
              int makeId;
              if (!kv.ContainsKey("Make") || !Int32.TryParse(kv["Make"], out makeId))
              {
                  return null;
              }             
              DataSet models = SqlHelper.ExecuteDataset(LITRMSConnection, "usp_GetSkillsList", new SqlParameter("@technology", makeId));
              for (int i = 0; i < models.Tables[0].Rows.Count; i++)
              {
                  values.Add(new CascadingDropDownNameValue(models.Tables[0].Rows[i]["Skill"].ToString(), models.Tables[0].Rows[i]["Technology"].ToString() + "," + models.Tables[0].Rows[i]["SkillID"].ToString()));
              }
          }
          catch (Exception ex)
          {

          }
        return values.ToArray();
      }
 i am getting values in to cascadingdropdown1 & cascadingdropdown2  but not able to set(selected Value) value in cascadingdropdown2.

我发现一个原因是,在rowcommand中绑定之后,它将被绑定到going ()。如何防止调用Getskills()。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-06-29 09:49:35

HiI可以找到答案,删除CascadingDropDown2 selectedValue Propery并编写行命令事件代码

代码语言:javascript
复制
int type = Convert.ToInt32(e.CommandArgument.ToString());
                    Label filename = (Label)grdindirectconsultant.Rows[type].Cells[1].FindControl("lblresume");
                    string txtfile = grdindirectconsultant.Rows[type].Cells[1].Text.ToString();
                    CascadingDropDown1.SelectedValue = grdindirectconsultant.Rows[type].Cells[8].Text.ToString();

                    txttechnology.SelectedItem.Value = grdindirectconsultant.Rows[type].Cells[8].Text.ToString();
                    Fillskills(); //Fill the primary skills depended up on the technology
                    CascadingDropDown2.SelectedValue = grdindirectconsultant.Rows[type].Cells[8].Text.ToString() + "," + grdindirectconsultant.Rows[type].Cells[9].Text.ToString();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11226831

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档