0

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

<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="" />

行命令事件代码

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();

网络服务方法

 [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 中绑定后它会转到 Getskills()。如何防止调用 Getskills()。

4

1 回答 1

0

Hi我可以找到答案,删除CascadingDropDown2 selectedValue 属性并编写行命令事件代码

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();
于 2012-06-29T09:49:35.573 回答