代码如下:
                <asp:Repeater ID="Repeater1" DataSourceID="sqldatasource2"  runat="server">
                
                <ItemTemplate>
                  <table width="100%" cellspacing="1" border="0" bgcolor="#0B198C">
<tr height="25" bgcolor="#435B8A" style="color:white">
<td colspan="2">
  #<asp:Label ID="labXH" runat="server" Text='<%# Container.ItemIndex + 1 %>' />
  <asp:Label ID="Label3" runat="server" Text='<%# Eval("ttime") %>' />
</tr>
<tr height="120">
<td class="td4" width="25%" bgcolor="#E1E4F2" valign="top">
<div style="font-size:14px;color:#0000FF">
  <asp:Label ID="Label6" Font-Bold="true" runat="server" Text='<%# Eval("loginname") %>' />
</div>
<div class="div3">
注册日期:
<asp:Label ID="Label7" runat="server" Text='<%# Eval("intime") %>' />
</div>
<div class="div3">
最后登录:
<asp:Label ID="Label8" runat="server" Text='<%# Eval("lastlogin") %>' />
</div>
<div class="div3">
发&nbsp;贴&nbsp;数:
<asp:Label ID="Label9" runat="server" Text='<%# Eval("tznum") %>' />
</div>
</td>
<td class="td4" width="75%" bgcolor="#F5F5FF" valign="top">
<div>
                                <asp:Image ID="Image2" ImageUrl='<%# Eval("icon","image/icon/{0}") %>' runat="server" />
                                <asp:Label ID="Label17" Font-Bold="true" runat="server" Text='<%# Eval("title") %>' />
                                <div style="float:right;"> 
                                    <asp:Button ID="Button2" runat="server" Text="删除" OnClick="delete_Click" /></div>
                                    <br />
                                    <br />
                                     <br />
<hr>
</div>
<div class="div1">
    <asp:Label ID="Label18" runat="server" Text='<%# SqlObj.FormatHTML(Eval("content").ToString()) %>' />
</div>
</td>
</tr>
   </table>                  
                </ItemTemplate>
                <SeparatorTemplate>
                    <br />
                </SeparatorTemplate>
                </asp:Repeater>然后它连接的sqldatasource2是:
 <asp:SqlDataSource 
        id="SqlDataSource2" 
        runat="server" 
        SelectCommand="select a.*,b.loginname,b.intime,lastlogin,(select count(*) from zhutiinfo where zhutiinfo.userid=a.userid)+(select count(*) from tiezhiinfo where tiezhiinfo.userid=a.userid) as tznum from tiezhiinfo a,userinfo b where a.userid=b.userid and ztid=@id order by ttime"
        ConnectionString="<%$ ConnectionStrings:CnnString%>" >
    <SelectParameters>
        <asp:QueryStringParameter Name="id" QueryStringField="id" />
    </SelectParameters>我想当我是管理员登录的时候,那个【删除】按钮才显示出来。 
<asp:Button ID="Button2" runat="server" Text="删除" OnClick="delete_Click" /></div>但是怎么将信息回传到服务器?告诉服务器我这次操作要删除的帖子ID (tiezhiinfo表里面的id这个字段) 是那一个?

解决方案 »

  1.   

    <asp:LinkButton runat="server" CommandArgument='<%#Eval("ID")%>' ID="lbtnDel" OnCommand="lbtnDel_Command">删除</asp:LinkButton>
    lbtnDel_Command事件中e.CommandArgument.ToString()为ID
      

  2.   

    顶二楼
    登录时 可以用session记录角色内容
    然后再在页面加载时判断角色
    是管理员的的话就遍历reperter 找到button
    设置display=block;
    否则为none
      

  3.   

    <asp:Button ID="Button2" runat="server" Text="删除" OnClick="delete_Click" Visible="<%# 判断是管理员() %>" />然后写代码protected bool 判断是管理员()
    {
        var context=Http.Current.Context;
        ......... //返回是否是管理员
    }
      

  4.   

    <asp:Button ID="Button2" runat="server" Text="删除" 
        OnClick="delete_Click" Visible="<%# 判断是管理员() %>" 数据id='<%# Eval("id") %>' />
    然后在事件处理方法中写void delete_Click(object sender, EventArgs e)
    {
        Button btn=(Button)sender;
        string id=btn.Attributes["数据id"];
    ........
    }
    这就获得了id。
      

  5.   

    ItemDataBound  事件里写    
      

  6.   

    另外,你应该首先使用DataList来实现这种东西,不要追求比需求更低级的工具自己手写一堆代码。使用DataList,直接用规范的删除功能就可以,不需要写几行代码。