如何获取Repeater1控件当前行数
前台代码:
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate><table border="1" bordercolor="#CCCCCC">
<tr bgcolor="Silver"><td>员工号</td><td>员工姓名</td><td>性别</td><td>年龄</td><td>职位</td><td>备注</td></tr></HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="lblid" runat="server" Text='<%#Eval("EmployeeID")%>'></asp:Label> </td>
<td> <%#Eval("Name")%> </td>
<td> <%#Eval("Sex")%> </td>
<td> <%#Eval("Age")%> </td>
<td> <%#Eval("PostName")%> </td>
<td> <asp:Button ID="btnMwssage" runat="server" Text="给TA留言" OnClick="btnMessage_Click"/> </td>
</tr>
</ItemTemplate>
<FooterTemplate></table></FooterTemplate>
</asp:Repeater>
后台代码:
protected void btnMessage_Click(object sender, EventArgs e)
{
for (int i =this.Repeater1.; i < this.Repeater1.Items.Count; i++)
{
int id = Convert.ToInt32(((Label)this.Repeater1.Items[i].FindControl("lblid")).Text);
string sql = "select Level from dbo.T_Level,dbo.T_EmployeInfo,dbo.T_EmployePost,dbo.T_Post where dbo.T_EmployeInfo.EmployeeID=dbo.T_EmployePost.EmployeeID and dbo.T_EmployePost.PostID=dbo.T_Post.PostID and dbo.T_Post.LevelID=dbo.T_Level.LevelID and dbo.T_EmployeInfo.EmployeeID=" + id + "";
int level = Convert.ToInt32(DbManager.ExecuteQuery(sql).Rows[0]["Level"]);
int id1 = Convert.ToInt32(Session["id"]);
string sql1 = "select Level from dbo.T_Level,dbo.T_EmployeInfo,dbo.T_EmployePost,dbo.T_Post where dbo.T_EmployeInfo.EmployeeID=dbo.T_EmployePost.EmployeeID and dbo.T_EmployePost.PostID=dbo.T_Post.PostID and dbo.T_Post.LevelID=dbo.T_Level.LevelID and dbo.T_EmployeInfo.EmployeeID=" + id1 + "";
int level1 = Convert.ToInt32(DbManager.ExecuteQuery(sql1).Rows[0]["Level"]);
if (level > level1)
Response.Write("<script>alert('对不起,您没有权限向该员工发送留言信息!')</script>");
else
Response.Redirect("PublishMessage.aspx?level=" + level);
}
}
我想请教高手,当我点击按钮时,如何知道是点击第几行的按钮,现在的问题是不管点击哪一行level 都始终只为一
求高手请教,急用
------解决方案--------------------
<asp:Button ID="btnMwssage" runat="server" Text="给TA留言" OnClick="btnMessage_Click"/>修改为 <asp:Button ID="Button1" runat="server" CommandArgument='<%#Eval("EmployeeID")%>' Text="Button"
oncommand="Button1_Command" />
protected void btnMessage_Click(object sender, EventArgs e)
修改为 protected void Button1_Command(object sender, CommandEventArgs e)
{
string employeeId = e.CommandArgument.ToString