Transforming data in for a repeater contro

Results 1 to 2 of 2

Thread: Transforming data in for a repeater contro

  1. #1
    Join Date
    Dec 1969

    Default Transforming data in for a repeater contro

    i am encountering a problem when i try to transform data using within an script. the script runs without error, but yet the specific control that is supposed to output the transformed data is not outputting anything onto the output page which does load other controls successfully. <BR><BR>specifically, i am pulling a single data record from a table that contains many boolean columns. that data is put into a table arbitrarily named "FAQs" in an dataset object. but since i need the data from that record in a different format, my script creates another table named "tblPracticeList" in the same dataset. my script then checks the value of each field in the record that was pulled up from the FAQs table and, if the boolean value is positive, my script then adds a row to the "tblPracticeList" table with an english language name for the element that the boolean field in the FAQs table represents.<BR><BR>this is very simple, even if it sounds complex. basically, i am "re-stacking" the data from the FAQs table so that it can be output in english on a web page. To do this, I am iterating through each of the boolean columns in the FAQs table and creating a new tblPracticeList table that contains a row with the english name for the element corresponding with each of the boolean columns in FAQs table that had positive values. If you understood prior to this paragraph, sorry for the repetition. I just wanted to make it explicit for anyone who didnt get it right away.<BR><BR>my problem, again, is that my script is not outputting any text. i can think of a number of possible causes, including the following:<BR>1.) the data from the boolean columns is not outputting properly when i use the command: Dim Iyengar As String = objDataset.Tables("FAQs").Columns("Iyengar").ToStr ing()<BR>2.) i am not using the appropriate syntax to test for fields that have positive boolean values when i use the command: IF Iyengar = "TRUE" THEN<BR>3.) data somehow is not being inputted into the tblPracticeList table when i use the command: myDataRow("Practices") = "Iyengar Yoga"<BR>objDataset.Tables("tblPracticeList").Rows .Add(myDataRow)<BR>4.) the data in the tblPracticeList table might not be binding properly to my repeater for output onto the page when i use the command: MyRepeater.DataSource = objDataset.Tables("tblPracticeList")<BR>MyRepeater .DataBind()<BR><BR>i am including all the relevant parts of my script below. this is from an ascx file, so it is just for the control that i am testing, and i have removed the largest section of the script so that there is nothing redundant below. the following includes everything in the script EXCEPT the redundant repetition that manually iterates through each of the boolean fields. the missing redundant section follows the model of the "Iyengar" section of code below.<BR><BR>can anyone show me what i am doing wrong and how to fix it?<BR><BR>i want there to be output on my web browser for this control and it is not giving me any, even though i have checked and there IS underlying data that should give me the output. the problem seems to be in the script below:<BR>-----------------------------------------------------------------<BR>&#060;% @Import Namespace="System.Data" %&#062;<BR>&#060;% @Import Namespace="System.Data.SqlClient" %&#062;<BR>&#060;script language="vb" runat="server"&#062;<BR> Sub Page_Load(sender as Object, e as EventArgs)<BR> &#039; Declare & populate variables<BR> Dim CenterID As String<BR> CenterID = Request( "pid" )<BR> Dim YogaTypeName As String<BR> Dim OrganizationID As String<BR> Dim sqlString As String<BR> Dim CenterStatus As String<BR> CenterStatus = "Active"<BR><BR> sqlString = "SELECT * " & _<BR> "FROM PracticeSummaries " & _<BR> "WHERE CenterID=" & CenterID<BR><BR> BindData(sqlString)<BR> End Sub <BR><BR> Sub BindData(sqlString As String)<BR> Dim myConnection As SqlConnection <BR> Dim objDataset As DataSet <BR> Dim objSQLDataAdapter As SQLDataAdapter <BR> Dim myCommand As SqlCommand <BR><BR> myConnection = New SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))<BR> myConnection.Open() <BR><BR> objSQLDataAdapter = New SqlDataAdapter() <BR> objDataset = New DataSet() <BR><BR> Dim strSQL as String = sqlString<BR><BR> myCommand = New SqlCommand(strSQL, myConnection) <BR> myCommand.CommandType = CommandType.Text <BR><BR> objSQLDataAdapter.SelectCommand = myCommand <BR> objSQLDataAdapter.Fill(objDataset, "FAQs") <BR>&#039; new code starts here<BR> Dim tblPracticeList As DataTable = objDataset.Tables.Add("tblPracticeList")<BR> tblPracticeList.Columns.Add("Practices", Type.GetType("System.String"))<BR><BR> Dim myDataRow As DataRow = objDataset.Tables("tblPracticeList").NewRow()<BR>< BR> Dim Iyengar As String = objDataset.Tables("FAQs").Columns("Iyengar").ToStr ing()<BR> Response.Write(Iyengar)<BR> IF Iyengar = "TRUE" THEN<BR> myDataRow("Practices") = "Iyengar Yoga"<BR> objDataset.Tables("tblPracticeList").Rows.Add(myDa taRow)<BR> END IF<BR>&#039; repeat the above 5 "iyengar" lines many times, one for each variable<BR><BR> MyRepeater.DataSource = objDataset.Tables("tblPracticeList")<BR> MyRepeater.DataBind()<BR> End Sub<BR><BR>&#060;/script&#062;<BR><BR>&#060;ASP:Repeater id="MyRepeater" runat="server"&#062;<BR> &#060;HeaderTemplate&#062;<BR> &#060;table&#062;<BR> &#060;tr&#062;<BR> &#060;td colspan="2" valign="top"&#062;<BR> &#060;H4&#062;&#060;b&#062;Practices available at this center:&#060;/b&#062;<BR><BR> &#060;ul&#062;<BR> &#060;/HeaderTemplate&#062;<BR> &#060;ItemTemplate&#062;<BR> &#060;li&#062;&#060;%# DataBinder.Eval(Container.DataItem, "Practices") %&#062;&#060;/li&#062;<BR> &#060;/ItemTemplate&#062;<BR> &#060;FooterTemplate&#062;<BR> &#060;/H4&#062;&#060;/ul&#062;<BR> &#060;/td&#062;<BR> &#060;/tr&#062;<BR> &#060;/table&#062;<BR> <BR><BR> &#060;/FooterTemplate&#062;<BR>&#060;/ASP:Repeater&#062;<BR>-----------------------------------------------------------------<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Transforming data in for a repeater co

    chef... there&#039;s quite a few *risky* areas in your code, but it wasn&#039;t realy a code review that you were after - and, anyways, I&#039;d be the last guy to be handing out code reviews :-)<BR><BR>Are you using Visual Studio? If you are, try stepping through the code and finding out the values at each code-point, that&#039;s the easiest way to debug and find out what&#039;s going wrong. For example, when you step through you will know if the code inside the following IF...THEN block is ever being evaluated:<BR><BR>IF Iyengar = "TRUE" THEN<BR> myDataRow("Practices") = "Iyengar Yoga"<BR> objDataset.Tables("tblPracticeList").Rows.Add(myDa taRow)<BR>END IF<BR><BR>Even if you are NOT using Visual Studio, you can get the same effect by sprinkling a few well placed Trace statements in the code to do the diagnostics.<BR><BR>Overall though, I&#039;d have to question your approach. Surely those named values that you are getting (i.e. "Iyengar Yoga") are stored in a normalized database structure and would be simply returned via an SQL JOIN?<BR><BR>It seems to me that you are *completely* re-doing what SQL&#039;s JOIN statement would give you for free... but you are doing it EXPENSIVELY!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts