首页 新闻 会员 周边 捐助

通讯录页面在学员没有照片的情况下可以显示默认照片

0
悬赏园豆:20 [已解决问题] 解决于 2015-07-29 09:17

前台代码:

<head runat="server">  <title>同学录</title>  <link href="../css/main.css" rel="stylesheet" />  <link rel="stylesheet" href="../css/css.css" />  <script type="text/javascript" src="../Js/jquery.js"></script>  <script language="javascript" type="text/ecmascript">                 function Order(field)         {             if(document.getElementById("hid_OrdFunction").value=="desc")             {                 //alert("a")                 document.getElementById("hid_OrdFunction").value="asc";             }             else             {                 document.getElementById("hid_OrdFunction").value="desc";             }             document.getElementById("hid_Field").value=field;             <%=this.Page.ClientScript.GetPostBackEventReference(this.Page,"")%>;         }  </script>

   <%--<script type="text/javascript">        function window.onload() {            var img = document.getElementById("td").getElementsByTagName("img");            for (var i = 0; i < img.length; i++) {                if (img[i].readyState == "uninitialized") {                    img[i].src = "Index/img/stuphoto.jpg";                        }            }        }        $(function () {            window.onload();        });    </script>--%>

 <style type="text/css">         <!--         body {          margin-left: 0px;          margin-top: 0px;          margin-right: 0px;          margin-bottom: 0px;         }         .Title         {             background-image:url(../images/wsj/oabg_05.gif);             height:21px;         }         .TitleCell         {             font-size:14px;         }         .Cell         {             font-size:12px;         }                  .table1 tr th         {text-align: center; font-weight: bold; color: #004B9B; border-bottom: 1px solid #1873BB; }         -->         .h3_3{background: url(../img/lm3_top.gif) no-repeat; padding-top: 8px;padding-bottom:11px;height:30px; position: relative;}     </style> </head> <body style="margin: 0px; overflow: auto;">  <form id="form1" runat="server">  <div class="div2">   <h3 class="h3_3" style="width: 760px;">    <%-- style="width:760px;"--%>    <span>     <asp:Literal ID="lt_t" runat="server" Text="班级通讯录"></asp:Literal></span>    <%if (System.Configuration.ConfigurationManager.AppSettings["ClientNameJC"].IndexOf("ZJDX") > -1)   { %>    <!--<a style= "cursor:Pointer; line-height: 32px; position: absolute; right: 130px; top: 0px; " onclick='javascript:location.href="HomePagenew1.aspx";' id="A1">[返回首页]</a>-->    <a style="cursor: Pointer; line-height: 32px; position: absolute; right: 0px; top: 0px;"     target="_blank" href="../Index/xybzsc.doc" id="A2">[帮助文档]</a>    <!--<a style= "cursor:Pointer; line-height: 32px; position: absolute; right: 0px; top: 0px; " target="_blank" href="mms://hydb.zjdx.gov.cn/xyhelp-v.wmv" id="ptbz_c">[帮助视频]</a>-->    <%} %>   </h3>   <div style="border: solid 1px #ddd; border-top: 0; background: url(../img/div2_bg.gif) left bottom repeat-x;    width: 760px; min-height: 517px; _height: expression(this.scrollHeight < 517? '517' : 'auto');">    <%--    <div style="overflow-x:hidden;overflow:auto;width:758px;height:515px;" >--%>    <input runat="server" type="hidden" id="hid_OrdFunction" value="asc" />    <input runat="server" type="hidden" id="hid_Field" />    <table border="0" align="center" cellpadding="0" cellspacing="0" width="100%">     <tr>      <td colspan="7" align="center" height="37">       <span style="font-size: 16px; font-style: normal; font-weight: bold; text-decoration: none;        color: #333333; font-family: Arial">        <asp:Literal ID="lt_title" runat="server" Text=""></asp:Literal>       </span>      </td>     </tr>     <tr valign="top">      <td>       <%        if (PhotoClassContactList)        {         for (int i = 0; i < DTTemp.Rows.Count; i++)         {          System.Data.DataRow row = DTTemp.Rows[i];        %>       <div style=" width:360px;font-size: 12px; margin-left:10px; margin-bottom:10px; line-height:35px;float:left;">        <table align="center" border="0" cellpadding="0" cellspacing="0"  class="table3">         <tr>          <td id="td" rowspan="4" style=" width:120px;" valign="top">          <img src="<%=System.Configuration.ConfigurationManager.AppSettings["UserPhotosSitePath"] + "/"+row["zppath"] %>" style="height:150px; width:120px;" /></td>          <td width="60px" style=" text-align:center;">姓名:</td>          <td width="*"><%=row["xm"] %></td>                                             </tr>         <tr>          <td style=" text-align:center;">电话:</td>          <td><%=row["SJHM"]%></td>         </tr>         <tr>          <td style=" text-align:center;">职务:</td>          <td><%=row["dw"]%></td>         </tr>         <tr>          <td style=" text-align:center;">单位:</td>          <td><%=row["zw"]%></td>         </tr>        </table>       </div>       <%}        }        else        { %>       <table align="center" style="font-size: 12px;" width="100%" cellpadding="0" cellspacing="0"        class="table1">        <tr class="Title">         <th align="center" style="cursor: hand; width: 90px;" onclick="Order('XM')" class="TitleCell">          姓名<asp:Literal ID="lit_XM" runat="server" EnableViewState="False"></asp:Literal>         </th>         <th align="center" style="cursor: hand;" onclick="Order('XB')" class="TitleCell">          性别<asp:Literal ID="lit_XB" runat="server" EnableViewState="False"></asp:Literal>         </th>         <th align="center" style="cursor: hand;" onclick="Order('DW')" class="TitleCell">          所在单位及职位<asp:Literal ID="lit_DW" runat="server" EnableViewState="False"></asp:Literal>         </th>         <th align="center" style="cursor: hand;" onclick="Order('SJHM')" class="TitleCell">          手机号<asp:Literal ID="lit_SJHM" runat="server" EnableViewState="False"></asp:Literal>         </th>         <% if (ConfigurationManager.AppSettings["ClientNameJC"].IndexOf("NBDX") == -1)      { %>         <th align="center" style="cursor: hand;" class="TitleCell">          QQ<asp:Literal ID="lit_QQ" runat="server" EnableViewState="False"></asp:Literal>         </th>         <%} %>         <th align="center" style="cursor: hand;" onclick="Order('FJH')" class="TitleCell">          房间号<asp:Literal ID="lit_FJH" runat="server" EnableViewState="False"></asp:Literal>         </th>         <th align="center" style="cursor: hand; width: 150px;" onclick="Order('CLASS')" class="TitleCell">          所在小组<asp:Literal ID="lit_CLASS" runat="server" EnableViewState="False"></asp:Literal>         </th>         <th align="center" class="TitleCell">          班委<asp:Literal ID="lit_ROLENAME" runat="server" EnableViewState="False"></asp:Literal>         </th>        </tr>        <asp:Repeater ID="Repeater1" runat="server">         <ItemTemplate>          <tr style="background-color: white; height: 22px;">           <td align="center" width="70" class="Cell">            <%#DataBinder.Eval(Container.DataItem,"XM")%>           </td>           <td align="center" width="40" nowrap class="Cell">            <%#DataBinder.Eval(Container.DataItem,"XB")%>           </td>           <td align="left" width="280" nowrap class="Cell">            <%#DataBinder.Eval(Container.DataItem,"DW")%>           </td>           <td align="center" width="100" nowrap class="Cell">            <%#DataBinder.Eval(Container.DataItem,"SJHM")%>           </td>           <% if (ConfigurationManager.AppSettings["ClientNameJC"].IndexOf("NBDX") == -1)           { %>           <td align="center" width="60" nowrap class="Cell">            <%#DataBinder.Eval(Container.DataItem,"QQ")%>           </td>           <%} %>           <td align="center" width="60" nowrap class="Cell">            <%#DataBinder.Eval(Container.DataItem,"FJH")%>           </td>           <td align="center" width="60" nowrap class="Cell">            <%#DataBinder.Eval(Container.DataItem, "CLASS")%>           </td>           <td align="center" width="60" nowrap class="Cell">            <%#DataBinder.Eval(Container.DataItem, "ROLENAME")%>           </td>          </tr>         </ItemTemplate>         <AlternatingItemTemplate>          <tr style="background-color: #f1f1f1; height: 22px;">           <td align="center" width="70" class="Cell">            <%#DataBinder.Eval(Container.DataItem,"XM")%>           </td>           <td align="center" width="40" nowrap class="Cell">            <%#DataBinder.Eval(Container.DataItem,"XB")%>           </td>           <td align="left" width="280" nowrap class="Cell">            <%#DataBinder.Eval(Container.DataItem,"DW")%>           </td>           <td align="center" width="100" nowrap class="Cell">            <%#DataBinder.Eval(Container.DataItem,"SJHM")%>           </td>           <% if (ConfigurationManager.AppSettings["ClientNameJC"].IndexOf("NBDX") == -1)           { %>           <td align="center" width="60" nowrap class="Cell">            <%#DataBinder.Eval(Container.DataItem,"QQ")%>           </td>           <%} %>           <td align="center" width="60" nowrap class="Cell">            <%#DataBinder.Eval(Container.DataItem,"FJH")%>           </td>           <td align="center" width="60" nowrap class="Cell">            <%#DataBinder.Eval(Container.DataItem, "CLASS")%>           </td>           <td align="center" width="60" nowrap class="Cell">            <%#DataBinder.Eval(Container.DataItem, "ROLENAME")%>           </td>          </tr>         </AlternatingItemTemplate>        </asp:Repeater>       </table>       <asp:Label ID="Lab_Clew" runat="server" Text="<br><font color='red'>您现在所在班级暂无同学!</font>"        Visible="False"></asp:Label>       <%} %>      </td>     </tr>     <tr>      <td align="right" height="30" style="font-size: 12px">       <cc1:PageChangeControl PageSize="100" ID="PageChangeControl1" runat="server" OnPageChanged="PageChangeControl1_PageChanged" />      </td>     </tr>    </table>   </div>  </div>  </form> </body> </html>

 

后台代码:

using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using DSOA.Class; using WebBaseLibrary;

namespace ZP_XYZZ.Index {     public partial class StudentMateRecords : BasePage     {   protected bool PhotoClassContactList =false;   protected DataTable DTTemp = new DataTable();         protected void Page_Load(object sender, EventArgs e)         {             SetUser(true);    PhotoClassContactList = DSOA.OA_help.SystemConfig.AppSettings["PhotoClassContactList"].ToLower() == "true";             try             {                 MyUser.ClassCollection classList = (MyUser.ClassCollection)myuser.ClassList;

                lt_title.Text = classList[0].Name;                 LoadData(classList[0].ClassID, myuser.UserID, "");

            }             catch (Exception ex)             {                 Response.Write("Error:" + ex.ToString());             }         }

        private void LoadData(string sClassID, string sUserID, string StrSort)         {             try             {     DataTable tbl = GetDTTbl(sClassID);                 if (tbl != null && tbl.Rows.Count > 0)                 {      DataTable dtC = GetDTC(tbl);

     if (PhotoClassContactList)      {       string order = string.Empty;       if (!String.IsNullOrEmpty((Request.Form["hid_Field"])) && hid_Field.Value != "CLASS")       {        order = hid_Field.Value + " " + hid_OrdFunction.Value;        string[] field = hid_Field.Value.Split('.');        Literal lit = (Literal)Page.FindControl("lit_" + field[field.Length - 1]);        if (lit != null)        {         if (hid_OrdFunction.Value == "asc")         {          lit.Text = "<img src='../images/up.gif'>";         }         else         {          lit.Text = "<img src='../images/down.gif'>";         }        }       }       else       {        string[] field = hid_Field.Value.Split('.');        Literal lit = (Literal)Page.FindControl("lit_" + field[field.Length - 1]);        if (lit != null)        {         if (hid_OrdFunction.Value == "asc")         {          lit.Text = "<img src='../images/up.gif'>";         }         else         {          lit.Text = "<img src='../images/down.gif'>";         }        }       }       DataTable dtA = new DataTable();       dtA = dtC.Clone();//克隆All的结构传递给dt       if (!string.IsNullOrEmpty(order))       {        foreach (DataRow dr in dtC.Select("1=1", order))        {         dtA.Rows.Add(dr.ItemArray);        }        DTTemp = dtA;        PageChangeControl1.DataSource = dtA.DefaultView;        Repeater1.DataSource = PageChangeControl1.PageChangedDataSource;        Repeater1.DataBind();       }       else       {        DTTemp = dtC;        PageChangeControl1.DataSource = dtC.DefaultView;        Repeater1.DataSource = PageChangeControl1.PageChangedDataSource;        Repeater1.DataBind();       }

      Repeater1.Visible = true;       Lab_Clew.Visible = false;      }                 }                 else                 {      if (PhotoClassContactList)      {       Repeater1.Visible = false;       Lab_Clew.Visible = true;      }                 }             }             catch (Exception ex)             {                 Response.Write("加载数据Error:" + ex.ToString());             }             finally             {                 m_cn.Close();             }         }

       

  private DataTable GetDTC(DataTable tbl)   {    DataColumn FIDCOL = new DataColumn("FID");    tbl.Columns.Add(FIDCOL);    DataColumn OrderNo = new DataColumn("ORD_NO");    tbl.Columns.Add(OrderNo);    DataColumn col = new DataColumn("CLASS");    tbl.Columns.Add(col);    DataColumn ROLENAME = new DataColumn("ROLENAME");    tbl.Columns.Add(ROLENAME);    DataColumn CLASSNAME = new DataColumn("CLASSNAME");    tbl.Columns.Add(CLASSNAME);    foreach (DataRow row in tbl.Rows)    {     //DateTime d = row["EDIT_TIME"] == DBNull.Value ? DateTime.MinValue : Convert.ToDateTime(row["EDIT_TIME"]);     //if (d.CompareTo(DateTime.Today) >= 0 && d.CompareTo(DateTime.Today.AddDays(1)) < 0)     //{     //    row["CLASSNAME"] = "Select";     //}     string stuyid = row["INFO_ID"].ToString();

    string sql = "select name from jw_classrole_rel rel inner join Jw_Classrole cl on rel.fid=cl.id and rel.bcinfo_id=cl.bcinfo_id where rel.rel_id=" + stuyid + " and rel.bcinfo_id=" + myuser.ClassList[0].ClassID;

    OleDbCommand cmd = new OleDbCommand(sql, m_cn);     OleDbDataReader ODR = cmd.ExecuteReader();     string role = "";     while (ODR.Read())     {      role += ODR[0].ToString() + "<br>";     }     row["ROLENAME"] = role;     ODR.Close();

    sql = "select wo.name,rel1.fid,rel1.ord_no from jw_classframework_rel rel1 inner join jw_classframework_rel rel2 on rel1.fid=rel2.id and rel1.bcinfo_id=rel2.bcinfo_id inner join Jw_Classframework wo on rel2.rel_id=wo.id and rel2.bcinfo_id=wo.bcinfo_id where rel1.rel_id=" + stuyid + " and rel1.bcinfo_id=" + myuser.ClassList[0].ClassID;     OleDbCommand cmdCl = new OleDbCommand(sql, m_cn);     OleDbDataReader ODRCl = cmdCl.ExecuteReader();     string Class = "";     string fid = string.Empty;     string orderno = string.Empty;     while (ODRCl.Read())     {      fid = ODRCl["FID"].ToString();      orderno = ODRCl["ORD_NO"].ToString();      Class += ODRCl["NAME"].ToString() + "<BR>";     }     row["FID"] = fid;     row["ORD_NO"] = orderno;     row["CLASS"] = Class;     ODRCl.Close();    }

   DataTable dtC = new DataTable();    dtC = tbl.Clone();//克隆All的结构传递给dt    int idx = 0;

   string strsql = "select * from vw_classframework where bcinfo_id=" + myuser.ClassList[0].ClassID + " ";    DataTable tbl1 = m_db.GetDataTable(strsql, m_cn);    DataRow[] rows = tbl1.Select(" fid=0 ", "ORD_NO");

   foreach (DataRow dr in rows)    {     strsql = "select t.* ,t1.name as zName from vw_classframework t inner join vw_classframework t1 on t.fid=t1.id  where   t.bcinfo_id=" + myuser.ClassList[0].ClassID + " and t.fid=" + dr["id"] + " order by t.ord_no ";     DataTable dtNew = m_db.GetDataTable(strsql, m_cn);     foreach (DataRow drNew in dtNew.Select("fid=" + dr["id"], "ORD_NO"))     {      foreach (DataRow DR in tbl.Select(" info_id= " + drNew["rel_id"], "ORD_NO"))      {       dtC.Rows.Add(DR.ItemArray);      }     }    }    foreach (DataRow dr in tbl.Select("CLASS = ''"))    {     dtC.Rows.Add(dr.ItemArray);    }    return dtC;   }

  private DataTable GetDTTbl(string sClassID)   {    string strSql = @"SELECT * FROM (         SELECT G2.BT AS XM,DECODE(XB,'0','男','女') AS XB,XY.SZDW AS DW,XY.ZW,ASCII(SUBSTR(G2.BT,1)) AS SHOWORDER         ,SUB.FJH,XY.SJHM,XY.QQ,SUB.FJDH,G2.ID AS INFO_ID,xy.zppath         FROM JW_BCGL BC         INNER JOIN G_INFOS G ON G.ID = BC.INFO_ID AND G.DELETED <> -1 AND BC.INFO_ID = " + sClassID+@"         INNER JOIN SUB_FILE_RELATION SUB ON SUB.FINFO_ID = BC.INFO_ID and sub.xxzt=0         INNER JOIN JW_XYXX XY ON XY.INFO_ID = SUB.INFO_ID         INNER JOIN G_INFOS G2 ON G2.ID = XY.INFO_ID AND G2.DELETED <> -1         WHERE XXZT<>1        ) ORDER BY SHOWORDER ASC";    DBInfo();    DataTable tbl = m_db.GetDataTable(strSql, m_cn);    return tbl;   }

        protected void PageChangeControl1_PageChanged(object sender, EventArgs e)         {             try             {                 MyUser.ClassCollection classList = (MyUser.ClassCollection)myuser.ClassList;                 LoadData(classList[0].ClassID, myuser.UserID, "");

            }             catch (Exception ex)             {                 Response.Write("Error:" + ex.ToString());             }         }     }

}

< >
分享
最佳答案
0

你前端都有判断语句了,你做一个判断,后台去查询数据,存在就把路径返回,不存在你就返回一个你自己定义的,就OK了

收获园豆:20
稳稳的河 | 老鸟四级 |园豆:4216 | 2015-07-27 17:09

我不会,你能给我写下代码吗?

漫天星星 | 园豆:114 (初学一级) | 2015-07-27 17:14

@漫天星星: 前端:

<div class="block">
<a href="/order/catalog"><img src="你传的" width="55" height="55" alt=""></a>
<p><a href="/order/catalog">Service Bureau ordering</a></p>
</div>

后台:一个方法返回路径就OK,怎么得到数据我过了说了,想动态什么的自己去做下,思路都提供了,没什么难度了

稳稳的河 | 园豆:4216 (老鸟四级) | 2015-07-27 18:09
其他回答(2)
0

加判断 你贴的这代码 。。。格式化一下 参考稳稳的河 

s_p | 园豆:140 (初学一级) | 2015-07-27 17:41
0

这代码一贴出来,估计  大家只能看热闹了

算了 | 园豆:3 (初学一级) | 2015-07-28 23:43
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册