0

I have two cascading dropdowns and one gridview control. on page load iam binding gridview, when i click on particular row iam trying to fill cascading dropdowns in Rowcommand event. aspx code

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

row command event code

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 service methods

 [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.

i found one reason is after binding in rowcommand it is going to Getskills(). How to prevent calling Getskills().

1 Answer 1

0

HiI can findout the answer, remove the CascadingDropDown2 selectedValue Propery and write the row command event Code

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.