Repeater使用:绑定时 结合 前台JS及后台共享方法

//前台模板
//如下
//图片结合了js
//lbl_DateStartEnd 的值 是直接绑定
//div的值 是由后绐共享的方法返回的HTML代码
<asp:Repeater ID="repeater_Show" runat="server">
            <ItemTemplate>
                <table width="100%">
                    <tr>
                        <td>
                            <a href="javascript:void hiddenlist('<%# Eval("CurrRowNum") %>')"
                            id="a<%# Eval("CurrRowNum") %>" title="隐藏">
                            <img id="img<%# Eval("CurrRowNum") %>" src="../Images/blue-chevron_up.gif"
                                border="0" align="absmiddle"  width="17" height="17"/></a> 
                            <asp:Label ID="lbl_DateStartEnd" runat="server" Text='<%# Eval("DateStartEnd") %>' ></asp:Label>
                            <asp:Label ID="lbl_YearAndWeek" runat="server" Text='<%# Eval("YearAndWeek") %>' ></asp:Label>
                        </td>                       
                    </tr>
                    <tr>
                        <td>
                            <div id='div<%# Eval("CurrRowNum") %>'>
                                <%# fn_bindWRBaseInfo(Convert.ToString(Eval("WRSeqID")))%>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div>
                                <%# fn_bindWRMonthSources(Convert.ToString(Eval("tSeqID")))%>
                            </div>
                        </td>
                    </tr>
                </table>
            </ItemTemplate>
        </asp:Repeater>

// JScript 文件
function hiddenlist(which)
{
   if (document.getElementById("div"+which).style.display=="")
   {
        document.getElementById("a"+which).title="展开"
  document.getElementById("div"+which).style.display="none"  
  document.getElementById("img"+which).src="../Images/blue-chevron_down.gif"
   }
   else
   {
  document.getElementById("a"+which).title="隐藏"
  document.getElementById("div"+which).style.display=""
  document.getElementById("img"+which).src="../Images/blue-chevron_up.gif"  
   }
}

//后台按钮事件
this.repeater_Show.DataSource = ds_1.Tables[0];
this.repeater_Show.DataBind();

//后台共享方法
protected string fn_bindWRBaseInfo(string strWRSeqID)
{       
    if (strWRSeqID == "0")
    {
        return "<font color='red'>没有填写 </font> ";
    }
    else
    {
 //跑数据库 取得相关值
        //组装成HTML代码 返回到前台
        //绑定到DIV
    }
}

原文地址:https://www.cnblogs.com/freeliver54/p/931182.html