一直覺得repeater不靈活,但是其實如果用后臺拼接html內(nèi)容的話,結合object類型,其實可以變化出多變的內(nèi)容。這里有個需求需要根據(jù)不同的基金經(jīng)理來綁定變動后的基金經(jīng)理內(nèi)容,每個基金經(jīng)理還有特定的ID用來拼接處html超鏈接來跳轉,困難來了,如果知道不同的內(nèi)容的基金經(jīng)理,是一個,二個或者多個呢,多個自然可以用逗號分隔,但是保存出來如何讓repeater綁定呢?。窟@里我采用了eval來實現(xiàn)。具體來看代碼:
首先要在實體類中定義一個標記字段和兩個用來存放基金經(jīng)理名的string數(shù)組或者僅僅是一個基金經(jīng)理,那用object對象最好不過,對于前段和中間都隱藏其具體含義,最后強綁定轉換就行,當然是根據(jù)標記字段來綁定。
- public class FundSubscriptionPeriodTip
- {
-
-
-
- public string NOTICEDATE { get; set; }
-
-
-
-
- public string FCODE { get; set; }
-
-
-
-
- public string SHORTNAME { get; set; }
-
-
-
-
- public string ISSBDATE { get; set; }
-
-
-
-
- public string ISSEDATE { get; set; }
-
-
-
-
- public string CHECKTIME { get; set; }
-
-
-
-
- public string CLOSETIME { get; set; }
-
-
-
-
-
-
- public string JJJLID { get; set; }
-
-
-
-
- public string JJJL { get; set; }
-
-
-
-
-
- public string ISSEDATEISSBDATE { get; set; }
-
-
-
-
- public object JJJLArray { get; set; }
-
-
-
-
-
-
-
- public object JJJLIDArray { get; set; }
-
-
-
-
- public string FundMangerNumber { get; set; }
-
- }
數(shù)據(jù)訪問層這邊就根據(jù)不同的基金經(jīng)理的數(shù)量來分隔或者直接賦值:- #region 基金認購期
- public static ResultInfo<List<FundSubscriptionPeriodTip>> GetFundSubscriptionPeriodTip()
- {
- ResultInfo<List<FundSubscriptionPeriodTip>> ret = new ResultInfo<List<FundSubscriptionPeriodTip>>();
-
- try
- {
- using (OracleConnection Conn = new OracleConnection(conn))
- {
- string sql;
- OracleCommand Cmd;
-
-
- sql = " select noticedate, " +
- " fcode," +
- " shortname, " +
- " ISSBDATE, " +
- " ISSEDATE, " +
- "''7個工作日'' checktime,"+
- "''一般3個月內(nèi)'' closetime,"+
- " jjjlid," +
- " jjjl " +
- " from fundadmin.fund_jbxx " +
- " where eisdel=0 and noticedate=to_date(sysdate)";
-
-
-
-
-
-
- Cmd = new OracleCommand(sql, Conn);
-
-
-
- Conn.Open();
- OracleDataAdapter oda = new OracleDataAdapter(Cmd);
- DataTable dtb = new DataTable();
- oda.Fill(dtb);
- List<FundSubscriptionPeriodTip> miLst = new List<FundSubscriptionPeriodTip>();
- foreach (DataRow row in dtb.Rows)
- {
- FundSubscriptionPeriodTip entity = new FundSubscriptionPeriodTip();
-
- entity.NOTICEDATE = Convert.ToDateTime((row["NOTICEDATE"])).ToShortDateString();
-
- entity.SHORTNAME = FormatTools.ParseString(row["SHORTNAME"]);
- entity.FCODE = FormatTools.ParseString(row["FCODE"]);
- entity.ISSBDATE = Convert.ToDateTime(row["ISSBDATE"]).ToShortDateString();
- entity.ISSEDATE = Convert.ToDateTime((row["ISSEDATE"])).ToShortDateString();
- entity.JJJLID=FormatTools.ParseString(row["JJJLID"]);
- entity.JJJL=FormatTools.ParseString(row["JJJL"]);
- entity.CHECKTIME = FormatTools.ParseString(row["CHECKTIME"]);
- entity.CLOSETIME = FormatTools.ParseString(row["CLOSETIME"]);
-
-
- <span style="color:#ff0000;"> if (!string.IsNullOrWhiteSpace(entity.JJJLID))
- if (entity.JJJLID.Contains(","))
- {
- entity.JJJLIDArray = entity.JJJLID.Split('','');
- entity.FundMangerNumber = "1";
- }
- else
- {
- entity.JJJLIDArray = entity.JJJLID.ToString();
- entity.FundMangerNumber = "0";
- }
- if (!string.IsNullOrWhiteSpace(entity.JJJL))
- if (entity.JJJL.Contains(","))
- entity.JJJLArray = entity.JJJL.Split('','');
-
- else
- entity.JJJLArray = entity.JJJL.ToString();
- an>
- miLst.Add(entity);
- }
-
- ret.SetValue(miLst);
- if (miLst.Count == 0)
- {
- ret.Message = "未查詢到任何記錄信息!";
- ret.SetValue(new List<FundSubscriptionPeriodTip>());
- }
- Conn.Close();
- }
- }
- catch (Exception e)
- {
- if (e != null)
- ret.Message += e.Message;
- }
-
- return ret;
-
- }
- #endregion
上面紅色部分是關鍵,后面是用前段來調用:- <tr>
- <td class="w200"> 基金經(jīng)理姓名 </td>
- <td class="pr200">
-
- <%-- <a href="http://fund.eastmoney.com/manager/<%#Eval("JJJLIDArray[0]")%>.html" target="_blank"> <%#Eval("JJJLArray[0]")%></a>,<a href="http://fund.eastmoney.com/manager/<%#Eval("JJJLIDArray[1]")%>.html" target="_blank"> <%#Eval("JJJLArray[1]")%></a>--%>
- <%#IsFundMangerNumber(Eval("FundMangerNumber").ToString(),Eval("JJJLIDArray"),Eval("JJJLArray"))%>
-
-
- </td>
- </tr>
后臺代碼就實際來拼接html內(nèi)容:
- public string IsFundMangerNumber(string FundMangerNumber, object JJJLIDArray, object JJJLArray)
- {
- string Show="";
- if (FundMangerNumber == "1")
- {
- for (int i = 0; i < ((string[])JJJLArray).Count(); i++)
- {
- Show = Show+" <a href=\"http://fund.eastmoney.com/manager/" + ((string[])JJJLIDArray)[i] + ".html\" target=\"_blank\">" + ((string[])JJJLArray)[i] + "</a>";
- if (i < (((string[])JJJLArray).Count()-1))
- Show = Show + ",";
- }
- }
- else
- {
- Show = Show + "<a href=\"http://fund.eastmoney.com/manager/" + JJJLIDArray + ".html\" target=\"_blank\">" + JJJLArray + "</a>";
-
- }
- return Show;
- }