[RESOLVED] a "how to go about it" question
Hi there,
I am creating this application and I need to print a receipt. Not a problem I have a proc that gets me all of the information I need. The most important to this question are this 1) The name of the main study the "section" came from and 2) the name of the "section" itself.
Now at the top of the page I set all the customer information, then underneath I set the name of the main study they purchased the section / sections from. After that is complete I set the data source of a repeater and we can see all of the sections they bought.
This solution works great if they bought everything from the one study. If they say purchased two sections from two studies how would I tell the page to print the name of other study right above the sections that came from that study? Make sense?
I can't really do that in a data repeater? I am not sure how to approach it?
Any suggestions would be great.
Thanks!
Re: a "how to go about it" question
You will modify your stored procedure such that in each row, it returns the study details as well as the section name. Order it by section name of course so that you can perform a .select() on the datatable.
Re: a "how to go about it" question
Hi there,
Yeah - the proc already returns the study name with each row. I am not too sure about the .select on the datatable can you explain a little further?
Thanks
Re: a "how to go about it" question
Sorry I wasn't clear, my bad.
You've made your call, you've gotten the rows, great.
Now, make another call to get the distinct values of the 'study name' of the rows. So you end up with "Study92" and "Study99" which have, say, 14 rows and 5 rows respectively.
Using these two distinct values you perform a .Select() on the datatable.
Code:
dt.Select("field2 = " + dtDistinct.Rows[0]["field2"].ToString());
Where would you use that code? In the ItemDataBound event of your repeater (which contains an ItemTemplate). You would use the dtDistinct to bind the DataRepeater, and the dt with the 'details' in it to fill up the items in the ItemTemplate.
Is that making sense? I could explain again...
Re: a "how to go about it" question
Well - This is actually what I ended up doing, hmm... i am sure you could argue that is isn't best practice however I do get points for creativity...
Code:
//Rebuild a new dataTable so we can show the StudyTitle if
//it is different from the first
string previousStudyIdNumber = ds.Tables[0].Rows[0]["StudyIdNumber"].ToString();
//just create three generic columns so that we can put whatever we need to into them
DataTable table = new DataTable();
table.Columns.Add("data1", typeof(string));
table.Columns.Add("data2", typeof(string));
table.Columns.Add("data3", typeof(string));
for (int i = 0; i <ds.Tables[0].Rows.Count; i++)
{
DataRow rptDr = ds.Tables[0].Rows[i];
if((!previousStudyIdNumber.Equals(rptDr["StudyIdNumber"])) || (i == 0))
{
//if the study numbers are different create a data row contianing the study info then
//create the datarow contianing the infomation about the part they purchased.
//once we are done with that reset the "previousStudy" variable to the current study...
string masterRecordInfo = "<b>Study Number: " + rptDr["StudyIdNumber"] + "<br /> Study Title: " + rptDr["StudyTitle"] + "<br /> Publication Date:" + rptDr["PublicationDate"] + "<br /></b>";
table.Rows.Add(new object[] { masterRecordInfo, "", "" });
table.Rows.Add(new object[] { " " + rptDr["Title"], "", rptDr["RetailPrice"], });
previousStudyIdNumber = rptDr["StudyIdNumber"].ToString();
} else {
//other wise just create a row with the info we need.
table.Rows.Add(new object[] { " " + rptDr["Title"], "", rptDr["RetailPrice"] });
}
}
//the go ahead and set the datasource like normal people world.
rptTransactionDetails.DataSource = table;
rptTransactionDetails.DataBind();
sqlConn.Close();
Thanks...
Re: [RESOLVED] a "how to go about it" question
Haha, yeah you do get points for creativity :D
If it works for you, that's fine.