Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Getting Relational Data from dataset and fill to dropdown

Posted on 2007-11-20
3
Medium Priority
?
979 Views
Last Modified: 2013-11-07
Hi,

I am working on C# using .Net 2.0

I have Dataset, In the DataSet oDst, I get 2 tables

I have made the realtion as below

DataSet oDst = oDynmcFld.GetFieldsByFormId("GetFieldsByFormId", 1);
oDst.Relations.Add("ControlValuesRelation", oDst.Tables[0].Columns["FieldId_PK"], oDst.Tables[1].Columns["FormFileds_Mstr_PK"]);


Now I have to create  Dropdown at runtime and add to the html form

I want the Data to be filled in drop down from the relation of the Dataset

As I did in my code like:

            drp = new DropDownList();
                drp.ID = oDt.Rows[iCnt]["FieldID"].ToString();
                drp.DataTextField = "FieldValue";
                drp.DataValueField = "FieldValue";

                drp.DataSource = oDst.Relations["ControlValuesRelation"].ChildTable.DefaultView; //.ChildRelations[oDt.Rows[iCnt]["FormFileds_Mstr_PK"].ToString()]; //.Contains(oDt.Rows[iCnt]["FieldId_PK"].ToString());
                drp.DataBind();
               
But this is filling all the Data present in oDst.Table[1], here I want the data from the Table[1] which matches the relation "ControlValuesRelation"


Please guide

Many Thanks

Here is my code below:



      oDynmcFld = new DynamicFieldBL();
      
        DataSet oDst = oDynmcFld.GetFieldsByFormId("GetFieldsByFormId", 1);
        oDst.Relations.Add("ControlValuesRelation", oDst.Tables[0].Columns["FieldId_PK"], oDst.Tables[1].Columns["FormFileds_Mstr_PK"]);
       
        DataTable oDt = oDst.Tables[0];

       HtmlTableRow htr = new HtmlTableRow();
       HtmlTableCell htc1 = new HtmlTableCell();
       HtmlTableCell htc2 = new HtmlTableCell();
       DropDownList drp = new DropDownList();
       
               
       int startWith = 6;
       

        if (oDt.Rows.Count > 0)
        {
            for (int iCnt = 0; iCnt <= oDt.Rows.Count - 1; iCnt++)
            {
                htr = new HtmlTableRow();
                htc1 = new HtmlTableCell();
                htc2 = new HtmlTableCell();

                sTempHTML += "<tr><td align=\"right\">";
                if (bool.Parse(oDt.Rows[iCnt]["IsMandatory"].ToString()))
                {
                    sTempHTML += "<font class=\"alert\">*</font> ";
                }
               
                drp = new DropDownList();
                drp.ID = oDt.Rows[iCnt]["FieldID"].ToString();
                drp.DataTextField = "FieldValue";
                drp.DataValueField = "FieldValue";

                drp.DataSource = oDst.Relations["ControlValuesRelation"].ChildTable.DefaultView; //.ChildRelations[oDt.Rows[iCnt]["FormFileds_Mstr_PK"].ToString()]; //.Contains(oDt.Rows[iCnt]["FieldId_PK"].ToString());
                drp.DataBind();

                htc2.Controls.Add(drp);

                htr.Cells.Add(htc1);
                htr.Cells.Add(htc2);
                DynamicTable.Rows.Insert(startWith, htr);
// DynamicTable is the Table Id in ASPX file <table width="100%" cellpadding="3" cellspacing="0" border="0" id="DynamicTable" runat="server" >
                startWith = startWith + 1;
              }
         }
oDynmcFld = new DynamicFieldBL();
	
        DataSet oDst = oDynmcFld.GetFieldsByFormId("GetFieldsByFormId", 1);
        oDst.Relations.Add("ControlValuesRelation", oDst.Tables[0].Columns["FieldId_PK"], oDst.Tables[1].Columns["FormFileds_Mstr_PK"]);
        
        DataTable oDt = oDst.Tables[0];
 
       HtmlTableRow htr = new HtmlTableRow();
       HtmlTableCell htc1 = new HtmlTableCell();
       HtmlTableCell htc2 = new HtmlTableCell();
       DropDownList drp = new DropDownList();
       
        
        drp.ID = "newDrp";
        drp.Items.Add(new ListItem("test"));
 
       int startWith = 6;
        
 
        if (oDt.Rows.Count > 0)
        {
            for (int iCnt = 0; iCnt <= oDt.Rows.Count - 1; iCnt++)
            {
                htr = new HtmlTableRow();
                htc1 = new HtmlTableCell();
                htc2 = new HtmlTableCell();
 
                sTempHTML += "<tr><td align=\"right\">";
                if (bool.Parse(oDt.Rows[iCnt]["IsMandatory"].ToString()))
                {
                    sTempHTML += "<font class=\"alert\">*</font> ";
                }
                
                drp = new DropDownList();
                drp.ID = oDt.Rows[iCnt]["FieldID"].ToString();
                drp.DataTextField = "FieldValue";
                drp.DataValueField = "FieldValue";
 
                drp.DataSource = oDst.Relations["ControlValuesRelation"].ChildTable.DefaultView; //.ChildRelations[oDt.Rows[iCnt]["FormFileds_Mstr_PK"].ToString()]; //.Contains(oDt.Rows[iCnt]["FieldId_PK"].ToString());
                drp.DataBind();
 
                htc2.Controls.Add(drp);
 
                htr.Cells.Add(htc1);
                htr.Cells.Add(htc2);
                DynamicTable.Rows.Insert(startWith, htr);
                startWith = startWith + 1;
              }
         }

Open in new window

0
Comment
Question by:tia_kamakshi
  • 2
3 Comments
 
LVL 3

Expert Comment

by:john_steed
ID: 20321772
Hi,

What you need to do is use getChildRows to get the childrows associated with a row in ds1
with drPublisher being one row in dataset1 and drPubsTitles being the relation as so :

drPublisher.GetChildRows(drPubsTitles)

hope this helps

0
 

Author Comment

by:tia_kamakshi
ID: 20321881
Thanks for your reply,

But GetChildRows is the property of DataRow

I do not have DataRow,

What code I should write here
drp = new DropDownList();
                drp.ID = oDt.Rows[iCnt]["FieldID"].ToString();
                drp.DataTextField = "FieldValue";
                drp.DataValueField = "FieldValue";

                drp.DataSource = oDst.Tables[1].getc
                drp.DataBind();

Thanks again
0
 
LVL 3

Accepted Solution

by:
john_steed earned 2000 total points
ID: 20322055
the datarelation between table 1 and 2 connects the records from table 1 to table 2 with FormFileds_Mstr_PK = FieldId_PK
so for each row in table 1 you get a few corresponding rows in table 2

do you want to show all records from table 2 that correspond with any row in table 1 ?

in that case you'll have to iterate through it
for each drRow in oDst.tables(0).rows
for each drChildRow in drRows.getChildRows(drRelation)
'add to dropdownlist
next
next
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question