2012-06-27 18 views
0

我有兩個級聯下拉菜單和一個gridview控件。在頁面加載iam綁定gridview, 當我點擊特定的行iam試圖填充Rowcommand事件中的級聯下拉列表。 ASPX代碼如何使用java腳本設置CascadingDropDown值

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

Web服務方法

[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()。

回答

0

HII可以findout答案,除去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();