.net怎么获取Repeater中lable的值
以前写过的,模糊记得一点,不多说了,我想某一行的Id,然后进行删除,可怎么也获取不到,应该是写错了吧,到底是哪里写错了?前台代码<asp:RepeaterID="repe...
以前写过的,模糊记得一点,不多说了,我想某一行的Id,然后进行删除,可怎么也获取不到,应该是写错了吧,到底是哪里写错了?
前台代码
<asp:Repeater ID="repeaterListSN" runat="server" >
<ItemTemplate>
<asp:Label ID="lblid" runat="server" Text="Label" Visible="false"><%#Eval("UserID") %></asp:Label>
<asp:LinkButton ID="lbtn" runat="server" oncommand="lbtn_Command">删除</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
后台代码
protected void lbtn_Command(object sender, CommandEventArgs e)
{
int id = Convert.ToInt32(((Label)this.repeaterListSN.FindControl("lblid")).Text);
Qol_UserInfo u = new Qol_UserInfo();
if (u.Delete(id))
{
Response.Write("<script>alert('删除成功');location='People.aspx'</script>");
}
else
{
Response.Write("<script>alert('删除失败')</script>");
}
} 展开
前台代码
<asp:Repeater ID="repeaterListSN" runat="server" >
<ItemTemplate>
<asp:Label ID="lblid" runat="server" Text="Label" Visible="false"><%#Eval("UserID") %></asp:Label>
<asp:LinkButton ID="lbtn" runat="server" oncommand="lbtn_Command">删除</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
后台代码
protected void lbtn_Command(object sender, CommandEventArgs e)
{
int id = Convert.ToInt32(((Label)this.repeaterListSN.FindControl("lblid")).Text);
Qol_UserInfo u = new Qol_UserInfo();
if (u.Delete(id))
{
Response.Write("<script>alert('删除成功');location='People.aspx'</script>");
}
else
{
Response.Write("<script>alert('删除失败')</script>");
}
} 展开
3个回答
展开全部
取repeater中label的值
方法一:
Label lblid=(Label )e.Item.FindControl("lblid");
lblid.Text //就可以取值啦
(注:这段代码的位置应该放在Repeater自带的方法中,e代表当前行,如ItemCommand,ItemDataBound)
方法二:
Label lblid=(Label )repeaterListSN.Items[i].FindControl("lblid");
lblid.Text //取值
(注:i代表第几行)
纠正一点,楼主的写法巩怕有点问题,对象获取不明确
其实这段代码可以更简单一点,供楼主参考一下
<asp:Repeater ID="repeaterListSN" runat="server"
onitemcommand="repeaterListSN_ItemCommand">
<ItemTemplate>
<tr>
<td>
<%#Eval("UserID") %>
<asp:LinkButton ID="lbtn" runat="server" CommandArgument='<%#Eval("UserID") %>' CommandName="delete">删除</asp:LinkButton><!--记住这里绑定值的时候一定要用单引号-->
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
后台代码:
后台
protected void repeaterListSN_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName=="delete")
{
int id=Convert.ToInt32(e.CommandArgument);
Qol_UserInfo u = new Qol_UserInfo();
if (u.Delete(id))
{
Response.Write("<script>alert('删除成功');location='People.aspx'</script>");
}
else
{
Response.Write("<script>alert('删除失败')</script>");
}
}
}
方法一:
Label lblid=(Label )e.Item.FindControl("lblid");
lblid.Text //就可以取值啦
(注:这段代码的位置应该放在Repeater自带的方法中,e代表当前行,如ItemCommand,ItemDataBound)
方法二:
Label lblid=(Label )repeaterListSN.Items[i].FindControl("lblid");
lblid.Text //取值
(注:i代表第几行)
纠正一点,楼主的写法巩怕有点问题,对象获取不明确
其实这段代码可以更简单一点,供楼主参考一下
<asp:Repeater ID="repeaterListSN" runat="server"
onitemcommand="repeaterListSN_ItemCommand">
<ItemTemplate>
<tr>
<td>
<%#Eval("UserID") %>
<asp:LinkButton ID="lbtn" runat="server" CommandArgument='<%#Eval("UserID") %>' CommandName="delete">删除</asp:LinkButton><!--记住这里绑定值的时候一定要用单引号-->
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
后台代码:
后台
protected void repeaterListSN_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName=="delete")
{
int id=Convert.ToInt32(e.CommandArgument);
Qol_UserInfo u = new Qol_UserInfo();
if (u.Delete(id))
{
Response.Write("<script>alert('删除成功');location='People.aspx'</script>");
}
else
{
Response.Write("<script>alert('删除失败')</script>");
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
前台
<asp:Repeater ID="repeaterListSN" runat="server"
onitemcommand="Repeater1_ItemCommand">
<ItemTemplate>
<tr>
<td>
<asp:Label ID="lblid" runat="server" Text='<%#Eval("UserID") %>' Visible="false"></asp:Label>
<asp:LinkButton ID="lbtn" runat="server" CommandName="delete">删除</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
后台
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName=="delete")
{
//删除方法
}
}
<asp:Repeater ID="repeaterListSN" runat="server"
onitemcommand="Repeater1_ItemCommand">
<ItemTemplate>
<tr>
<td>
<asp:Label ID="lblid" runat="server" Text='<%#Eval("UserID") %>' Visible="false"></asp:Label>
<asp:LinkButton ID="lbtn" runat="server" CommandName="delete">删除</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
后台
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName=="delete")
{
//删除方法
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
代码
前台:
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table class="Repeater_Table" cellpadding="0" cellspacing="0" border="1">
<tr class="Repeater_Tr">
<th class="Repeatertd">
选择
</th>
<th class="Repeatertd">
报送名称
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr align="center" class="GhbsTr">
<td class="Repeater_Td">
<asp:CheckBox ID="cb_id" CssClass="checkall" runat="server" />
<asp:Label ID="lb_uid" runat="server" Text='<%#Eval("UserID" )%>' Visible="False"></asp:Label>
</td>
<td class="ReapteTd">
<asp:Label ID="lblTiaoxingma" runat="server" Text='<%#Eval("sendName") %>'></asp:Label>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
后台:
#region 批量删除按钮
private bool IsChecked = false;
protected void lbtnDel_Click(object sender, EventArgs e)
{
try
{
for (int i = 0; i < Repeater1.Items.Count; i++)
{
string lbUid = ((Label)Repeater1.Items[i].FindControl("lb_uid")).Text;
string lbSendName = ((Label)Repeater1.Items[i].FindControl("lb_sendName")).Text;
CheckBox cb = (CheckBox)Repeater1.Items[i].FindControl("cb_id");
if (cb.Checked)
{
IsChecked = true;
imcpbll.DelPbpbj( lbUid ,lbSendName );
}
}
if (IsChecked)
{
JscriptPrint("信息批量删除成功啦!", "", "Success");
SendNameSelect();
log.AddLogrecord("质量与可靠性信息管理模块", "产品校验情况信息", "删除", "信息批量删除,操作成功!", "Exam.aspx");
}
else
{
JscriptPrint("请选择您要删除的信息!", "", "lose");
log.AddLogrecord("质量与可靠性信息管理模块", "产品校验情况信息", "删除", "信息批量删除,操作失败!", "Exam.aspx");
}
}
catch
{
log.AddLogrecord("质量与可靠性信息管理模块", "产品校验情况信息", "删除", "信息批量删除,操作失败!", "Exam.aspx");
return;
}
}
#endregion
祝你好运!
前台:
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table class="Repeater_Table" cellpadding="0" cellspacing="0" border="1">
<tr class="Repeater_Tr">
<th class="Repeatertd">
选择
</th>
<th class="Repeatertd">
报送名称
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr align="center" class="GhbsTr">
<td class="Repeater_Td">
<asp:CheckBox ID="cb_id" CssClass="checkall" runat="server" />
<asp:Label ID="lb_uid" runat="server" Text='<%#Eval("UserID" )%>' Visible="False"></asp:Label>
</td>
<td class="ReapteTd">
<asp:Label ID="lblTiaoxingma" runat="server" Text='<%#Eval("sendName") %>'></asp:Label>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
后台:
#region 批量删除按钮
private bool IsChecked = false;
protected void lbtnDel_Click(object sender, EventArgs e)
{
try
{
for (int i = 0; i < Repeater1.Items.Count; i++)
{
string lbUid = ((Label)Repeater1.Items[i].FindControl("lb_uid")).Text;
string lbSendName = ((Label)Repeater1.Items[i].FindControl("lb_sendName")).Text;
CheckBox cb = (CheckBox)Repeater1.Items[i].FindControl("cb_id");
if (cb.Checked)
{
IsChecked = true;
imcpbll.DelPbpbj( lbUid ,lbSendName );
}
}
if (IsChecked)
{
JscriptPrint("信息批量删除成功啦!", "", "Success");
SendNameSelect();
log.AddLogrecord("质量与可靠性信息管理模块", "产品校验情况信息", "删除", "信息批量删除,操作成功!", "Exam.aspx");
}
else
{
JscriptPrint("请选择您要删除的信息!", "", "lose");
log.AddLogrecord("质量与可靠性信息管理模块", "产品校验情况信息", "删除", "信息批量删除,操作失败!", "Exam.aspx");
}
}
catch
{
log.AddLogrecord("质量与可靠性信息管理模块", "产品校验情况信息", "删除", "信息批量删除,操作失败!", "Exam.aspx");
return;
}
}
#endregion
祝你好运!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询