Repeater如何取出某一列的值

tang511558 2011-11-17 02:39:00
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Show.aspx.cs" Inherits="web.Web.ewsAdmin.aspx.article.Show" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<link rel="stylesheet" type="text/css" href="../../skin/css/base.css" />
<script language="javascript" type="text/javascript">
function viewArc(aid){
if(aid==0) aid = getOneItem();
window.open("archives.asp?aid="+aid+"&action=viewArchives");
}
function editArc(aid){
if(aid==0) aid = getOneItem();
location="archives.asp?aid="+aid+"&action=editArchives";
}
function updateArc(aid){
//var qstr=getCheckboxItem();
//if(aid==0) aid = getOneItem();
//location="archives.asp?aid="+aid+"&action=makeArchives&qstr="+qstr+"";
location="show.aspx"; //?aid="+aid+"&action=makeArchives&qstr="+qstr+"";
}
function checkArc(aid){
var qstr=getCheckboxItem();
if(aid==0) aid = getOneItem();
location="archives.asp?aid="+aid+"&action=checkArchives&qstr="+qstr+"";
}
function moveArc(aid){
var qstr=getCheckboxItem();
if(aid==0) aid = getOneItem();
location="archives.asp?aid="+aid+"&action=moveArchives&qstr="+qstr+"";
}
function adArc(aid){
var qstr=getCheckboxItem();
if(aid==0) aid = getOneItem();
location="archives.asp?aid="+aid+"&action=commendArchives&qstr="+qstr+"";
}
function delArc(aid){
var qstr=getCheckboxItem();
if(aid==0) aid = getOneItem();
location="archives.asp?aid="+aid+"&action=delArchives&qstr="+qstr+"";
}

//获得选中文件的文件名
function getCheckboxItem()
{
var allSel="";
if(document.form1.id.value) return document.form1.id.value;
for(i=0;i<document.form1.id.length;i++)
{
if(document.form1.id[i].checked)
{
if(allSel=="")
allSel=document.form1.id[i].value;
else
allSel=allSel+"`"+document.form1.id[i].value;
}
}
return allSel;
}

//获得选中其中一个的id
function getOneItem()
{
var allSel="";
if(document.form1.id.value) return document.form1.id.value;
for(i=0;i<document.form1.id.length;i++)
{
if(document.form1.id[i].checked)
{
allSel = document.form1.id[i].value;
break;
}
}
return allSel;
}
function selAll()
{
for(i=0;i<document.form1.id.length;i++)
{
if(!document.form1.id[i].checked)
{
document.form1.id[i].checked=true;
}
}
}
function noSelAll()
{
for(i=0;i<document.form1.id.length;i++)
{
if(document.form1.id[i].checked)
{
document.form1.id[i].checked=false;
}
}
}

</script>
</head>
<body>
<form id="form1" runat="server">
<table width="98%" border="0" cellpadding="2" cellspacing="1" bgcolor="#D1DDAA" align="center"
style="margin-top: 8px">
<tr bgcolor="#E7E7E7">
<td height="24" colspan="10" background="../../skin/images/wbg.gif">
 所有文章列表 
</td>
</tr>
<asp:Repeater ID="artList" runat="server" onitemcommand="artList_ItemCommand" >
<HeaderTemplate>
<tr align="center" bgcolor="#FAFAF1" height="22">
<td >选择
</td>
<td >ID
</td>
<td>
标题
</td>
<td >
类别
</td>
<td>
置顶
</td>
<td>
审核
</td>
<td >
简介
</td>
<td>
作者
</td>
<td>
时间
</td>
<td>
操作
</td>
</tr>

</HeaderTemplate>
<ItemTemplate>
<tr align='center' bgcolor="#FFFFFF" onmousemove="javascript:this.bgColor='#FCFDEE';"
onmouseout="javascript:this.bgColor='#FFFFFF';" height="22">
<td>
<asp:CheckBox ID="checkbox1" runat="server" class="np"/>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "ID")%>
</td>
<td align="left">
<%# DataBinder.Eval(Container.DataItem, "newtitle")%>
</td>
<td>
<%# ( DataBinder.Eval(Container.DataItem, "type"))%>
</td>
<td>
<%# setTop( DataBinder.Eval(Container.DataItem, "OrTop").ToString())%>
</td>
<td>
<%# setCheck( DataBinder.Eval(Container.DataItem, "isHits").ToString())%>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "ZaiYao")%>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "Author")%>
</td>
<td>
<%# cutDate (DataBinder.Eval(Container.DataItem, "addTime").ToString())%>

</td>
<td>
<a href="Modfiy.aspx?id=<%# DataBinder.Eval(Container.DataItem, "ID")%>">编辑</a> | <a href=" ../../../<%# DataBinder.Eval(Container.DataItem, "ID")%> ">预览</a>
</td>
</tr>

</ItemTemplate>
<FooterTemplate> <tr bgcolor="#FAFAF1">
<td height="28" colspan="10">
  <a href="javascript:selAll()" class="coolbg">全选</a> <a href="javascript:noSelAll()"
class="coolbg">取消</a> <a href="javascript:updateArc()" class="coolbg"> 更新 </a> <a href="javascript:delArc(0)" class="coolbg"> 删除 </a>
</td>
</tr>

</FooterTemplate>

</asp:Repeater>
<tr align="right" bgcolor="#EEF4EA">
<td height="36" colspan="10" align="center">
<asp:LinkButton ID="lbtnFirstPage" runat="server" onclick="lbtnFirstPage_Click" >页首</asp:LinkButton>
<asp:LinkButton ID="lbtnpritPage" runat="server" onclick="lbtnpritPage_Click" >上一页</asp:LinkButton>
<asp:LinkButton ID="lbtnNextPage" runat="server" onclick="lbtnNextPage_Click" >下一页</asp:LinkButton>
<asp:LinkButton ID="lbtnDownPage" runat="server" onclick="lbtnDownPage_Click" >页尾</asp:LinkButton>   
第<asp:Label ID="labPage" runat="server" Text="Label"></asp:Label>页/共<asp:Label ID="LabCountPage" runat="server" Text="Label"></asp:Label>



<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="删除" OnClientClick="return confirm('确认删除?')" />

</td>
</tr>
</table>
</form>
</body>
</html>


我想在.ASPX.CS里面获取<%# DataBinder.Eval(Container.DataItem, "ID")%>
ID的值,
...全文
215 17 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
tang511558 2011-11-17
  • 打赏
  • 举报
回复
好的。,解决了啊,谢谢
dongt1 2011-11-17
  • 打赏
  • 举报
回复
那个label必须放在你的控件里面绑定你的id
dongt1 2011-11-17
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 tang511558 的回复:]
是啊,二楼的那个不行,出现这个问题“未将对象引用设置到对象的实例” 还有Repeater1.Rows.Count; i++ 没有ROWS这个名称。
[/Quote]你得拖上去一个label
dongt1 2011-11-17
  • 打赏
  • 举报
回复
labl.Text;这是一个asp:label控件你难道没写
tang511558 2011-11-17
  • 打赏
  • 举报
回复
是啊,二楼的那个不行,出现这个问题“未将对象引用设置到对象的实例” 还有Repeater1.Rows.Count; i++ 没有ROWS这个名称。
dongt1 2011-11-17
  • 打赏
  • 举报
回复
2楼得不行???怀疑了
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 libo0952 的回复:]

protected void Page_Load(object sender, EventArgs e)
{
int sum = 0;
for (int i = 0; i < Repeater1.Rows.Count; i++)
{

sum+=Convert.ToInt32(Repeater1.Rows[……
[/Quote]
tang511558 2011-11-17
  • 打赏
  • 举报
回复
还有我的是VS2008。各位达人些,帮帮忙啊。、
tang511558 2011-11-17
  • 打赏
  • 举报
回复
不行啊。我就是想,通过获取。<%# DataBinder.Eval(Container.DataItem, "ID")%>
ID的值,来删除这条数据
tang511558 2011-11-17
  • 打赏
  • 举报
回复
未将对象引用设置到对象的实例。出现这个问题
libo0952 2011-11-17
  • 打赏
  • 举报
回复
protected void Page_Load(object sender, EventArgs e)
{
int sum = 0;
for (int i = 0; i < Repeater1.Rows.Count; i++)
{

sum+=Convert.ToInt32(Repeater1.Rows[i].Cells[4].Text.ToString());
}
TextBox1.Text = sum.ToString();
}
可执行
【拿不拿分不要紧,希望某些人不要昧着良心来骗分
骗分是小,误导所有关心这问题的人是大
我不是为了分而来,但最后很多人愿意把分给我!
谢谢各位,让我成为上升最快达人!】
BIRD72sky 2011-11-17
  • 打赏
  • 举报
回复
顶下,gridview的知道,repeater的不知道,呵呵
  • 打赏
  • 举报
回复
前台:<ItemTemplate>
<tr class="tdRow" id="<%#Eval("RecID") %>" onclick="GetID('<%#Eval("ID") %>');>


外部放一个隐藏空间来取ID的值;
js:
GetRecID(id)
{
document.getElementById("隐藏控件id").value = id;
}
取值:
int id=int。parse(隐藏控件id.value);
dongt1 2011-11-17
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 chaichangaini 的回复:]
C# code
你用个label 把ID绑定在Lable的Text上
//后台代码
for (int a = 0; a < this.Repeater1.Items.Count; a++)
{
Label labl = this.Repeater1.Items[0].FindControl("lable") as Label;
//这就得到了ID
string……
[/Quote]
q107770540 2011-11-17
  • 打赏
  • 举报
回复
foreach(RepeaterItem item in Repeater1.Items)
{
item.dataitem["ID"]
}
1800包吃包住 2011-11-17
  • 打赏
  • 举报
回复
你用个label 把ID绑定在Lable的Text上
//后台代码
for (int a = 0; a < this.Repeater1.Items.Count; a++)
{
Label labl = this.Repeater1.Items[0].FindControl("lable") as Label;
//这就得到了ID
string ID=labl.Text;
}
1800包吃包住 2011-11-17
  • 打赏
  • 举报
回复
你用个label 把ID绑定在Lable的Text上
//后台代码
for (int a = 0; a < this.Repeater1.Items.Count; a++)
{
Label labl = this.Repeater1.Items[0].FindControl("lable") as Label;
//这就得到了ID
string ID=labl.Text;
}

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧