However, the problem is that the subjects of different departments are not the same, then we are in the database design is usually the students, a certain subjects as a record, then we need to do a row of the logical processing of the column.
Workaround:
Using the GridView to generate the form, this implementation will be more cumbersome, if you want to display a link in the list is even more impossible;
Generate HTML and then output to the page, this implementation is more flexible and convenient;
Basic function Points:
dynamically generating table headers;
Data paging;
query data;
A hyperlink to each result to view the details;
Page code
Copy Code code as follows:
<div id= "DataDiv1" >
<asp:literal id= "labtable" runat= "Server" ></asp:Literal>
<div class= "Toolblock" style= "Border-top:solid 1px #C0CEDF; padding-top:5px ">
<bw:virtualpager id= "VirtualPager1" runat= "Server" itemsperpage= "onpageindexchanged=" virtualpager1_ PageIndexChanged "/>
</div>
</div>
Background code (generates an HTML string)
Copy Code code as follows:
<summary>
Table method to load the evaluation results.
STEP1: Get the only batch through the years.
STEP2: Generate header.
STEP3: Start looping each user.
STEP4: Loops each user's assessment.
</summary>
protected void bindtable ()
{
Labtable. Text = string. Empty;
Get the only batch through the years.
String year = Dropdownimportyear.selectedvalue;
String month = Dropdownimportmonth.selectedvalue;
String group_kh_date = year + month;
Groupservice groupservice = new Groupservice ();
DataTable Dtgroup = groupservice.getbytemplatecodeandgroup_kh_date (Templatecode, group_kh_date);
if (DtGroup.Rows.Count > 0)
{
GUID GroupID = (GUID) dbutils.toguid (dtgroup.rows[0]["ID"]);
int groupstutas = Dbutils.toint32 (dtgroup.rows[0]["Groupstutas"). ToString ());
DataTable dtcells = Personalgradeservice.getdistincttemplateitemnamebygroupid (GroupID);
GroupID = Groupid.tostring ();
if (DtCells.Rows.Count > 0)
{
int cellscount = 0;//number of check items.
StringBuilder strtable = new StringBuilder ();
Strtable. AppendFormat ("<table cellpadding=\" 0\ "cellspacing=\" 0\ "class=\" tblclass\ ">");
Strtable. AppendFormat ("<tr>");
Strtable. AppendFormat ("<th> User name </th></span>");
Cellscount = DtCells.Rows.Count;
for (int i = 0; i < Cellscount; i++)
{
Strtable. AppendFormat ("<th>{0}</th>", dtcells.rows[i]["Name"). ToString ());
}
Strtable. AppendFormat ("</tr>");
DataTable dtgradedata = GetData (Cellscount);
int cursor = 1;//represents the first record of a user.
String userName = String. Empty;
String realname = String. Empty;
for (int i = 0; i<dtgradedata.rows.count; i++)
{
if (cursor = 1)
{
UserName = dtgradedata.rows[i]["UserName"]. ToString ();
Realname = dtgradedata.rows[i]["Realname"]. ToString ();
Strtable. AppendFormat ("<td width=\" 12%\ ">{0}</td>", realname);
}
String id = dtgradedata.rows[i]["id"]. ToString ();
String templateitemcode = dtgradedata.rows[i]["Templateitemcode"]. ToString ();
Strtable. AppendFormat ("<td width=\" 50px\ ">");
String gradedata = dtgradedata.rows[i]["Gradedata"]. ToString ();
if (!string. IsNullOrEmpty (gradedata) && gradedata!= "0")
{
Gradedata=math.round (decimal. Parse (Gradedata), 2). ToString ();
Convert to two decimal places
}
Strtable. AppendFormat ("{0}", Gradedata);
Unpublished results can be modified
if (groupstutas!= (int) Botwave.MRPS.Constants.GroupStutas.FinishPush)
{
Strtable. AppendFormat ("<br/><a style=\" text-decoration:underline\ "class=\" thickbox\ "href=" Usergradedataedit.aspx?id={0}&bemodifer={1}&keepthis=true&tb_iframe=true&height=250&width= ">", ID, userName);
Strtable. AppendFormat ("Strtable. AppendFormat ("</a>");
}
Strtable. AppendFormat ("<a target=\" _blank\ "style=\" text-decoration:underline\ "href=" http://www.cnblogs.com/ Checkobjectmanager/pages/logscorechangedetail.aspx? Groupid={0}&templatecode={1}&templateitemcode={2}&username={3}&returnurl= ' > ', GroupId, Templatecode, Templateitemcode, userName);
Strtable. AppendFormat ("Strtable. AppendFormat ("</a>");
Strtable. AppendFormat ("</td>");
if (Cursor < cellscount)
cursor++;
Else
{
Strtable. AppendFormat ("</tr>");
cursor = 1;
}
}
Strtable. AppendFormat ("</table>");
Labtable. Text = strtable. ToString ();
}
}
}
Several auxiliary methods (how to deal with the paging problem, which is related to the use of Cellscount parameters, Cellscount represents the number of subjects)
Copy Code code as follows:
protected void btnSearch_Click (object sender, EventArgs e)
{
Searchnow = true;
Virtualpager1.currentpageindex = 1;
Bindtable ();
}
protected void Virtualpager1_pageindexchanged (object sender, Botwave.Web.Controls.PageChangedEventArgs e)
{
Bindtable ();
}
<summary>
Get the test results.
</summary>
<returns></returns>
Private DataTable GetData (int cellscount)
{
int nrecordcount = 0;
String condition = "";
String filtername = TxtUserName.Text.Trim ();//Name search.
StringBuilder sb = new StringBuilder ();
Sb. AppendFormat ("GroupID = ' {0} '", GroupID);
if (!string. IsNullOrEmpty (FilterName))
Sb. AppendFormat ("and (UserName like '%{0}% ' OR realname like '%{0}% ')", filtername);
Condition = sb. ToString ();
if (Searchnow)//When on many pages, or the last page, this time to click on the query, it will be an error currentpageindex, this approach is to prevent this.
Virtualpager1.currentpageindex = 0;
DataTable dt = Personalgradeservice.getgradedata (Virtualpager1.currentpageindex, Virtualpager1.itemsperpage * Cellscount, condition, ref nrecordcount);
Virtualpager1.totalrecordcount = Nrecordcount/cellscount;
Virtualpager1.databind ();
Searchnow = false;//to be copied again.
return DT;
}
Business logic (pagination)
Copy Code code as follows:
Public System.Data.DataTable getgradedata (int currentpageindex, int pageSize, string condition, ref int nrecordcount)
{
String fieldshow = "Userid,templatecode,templateitemcode,gradedata,id,username,realname";
String fieldorder = "UserName asc,templateitemcode ASC";
string where = condition;
if (String.IsNullOrEmpty (where))
{
where = "1=1";
}
Return Ibatisdbhelper.getpagedlist ("Dbo.vw_usergradedata", "ID", CurrentPageIndex, PageSize, Fieldshow, Fieldorder, where, ref nrecordcount);
}
Precautions:
When using the <asp:literal id= "labtable" runat= "server" ></asp:Literal> to output HTML on the page to display the form, note the length of the string, if the HTML is too long, There will be a mistake, because the literal has a limit of 8,000 characters;
The data is sorted well in the database so that the data is one by one corresponding to the header.
Here is a premise, that is, the query data are included in the same number of records, such as classmate A and classmate B of the subject is as much; because it is not as much, then the dynamic form doesn't make sense. If there is a difference, it can be done, but it will be a bit of trouble;