c# - Can't get Heads to show with only one record -
i pulling down records have count of 0 or more 1. query works , pulls down , looks great in sql results. looping through results , creating header , grouping them based on country , listing name of users country.
this sql:
select * ( select u.contactname ,cu.[user id] ,c.name ,c.id ,cu.[foreign table] ,count(*) on (partition c.id) user_in_this_country dbo.country c inner join dbo.countryuser cu on c.id = cu.[foreign id] inner join dbo.usercolder u on cu.[user id] = u.id exists ( select * countryuser cu2 cu2.[foreign id] = cu.[foreign id] , cu2.[user id] <> cu.[user id] , cu2.[foreign table] = 'country') ) t user_in_this_country > 1 or user_in_this_country = 0 order name asc
this pull down data like:
justin united states 2 bob united states 2
then method loop through , add headers/group is:
string lastvalue = ""; protected string addgroupingheader(string value) { //get data field value of interest row string currentvalue = value; //specify name display if datafieldvalue database null if (currentvalue.length == 0) { currentvalue = ""; } //see if there's been change in value if (lastvalue != currentvalue) { //there's been change! record change , emit header lastvalue = currentvalue; return "<div style='float: left; font-size: 16px; margin: 10px 0px 0px 10px;'>" + currentvalue + "</div>"; } else { return ""; } }
and in aspx passing value so:
<%# addgroupingheader(eval("name").tostring())%>
now if have several records works propery , displays like:
united states - justin - bob china - frank - ted
but , problem. if have:
united states justin united bob
then doesn't put header. this:
justin bob
sorry long post, see cause this, i've been stumped 2 days. :(
thanks!
remove float
style. method addgroupingheader
can simplified. call passing value, serves header.
string _lastheader; protected string addgroupingheader(string header) { if (header != _lastheader) { _lastheader = header; return "<div style='font-size: 16px; margin: 10px 0px 0px 10px;'>" + header + "</div>"; } return ""; }
Comments
Post a Comment