(来者有分)特急,关于DataList的选中及取值问题
朋友们:以下为我的DataList项目模板绑定方法:我现在有两个问题请教大家:
第一个问题:我如何才能选中一行;
第二个问题:我如何才能得到选中列中的值(我估计肯定用到FindCtrol()方法),用什么事件?请高手朋友帮忙.
<ItemTemplate>
<TABLE id= "table2 " style= "FONT-SIZE: 12px; CURSOR: hand " borderColor= "#efefef " height= "18 "
cellSpacing= "0 " cellPadding= "0 " width= "100% " bgColor= "white " border= "0 ">
<TR onmouseover= "this.bgColor= '#efefef '; " onmouseout= "this.bgColor= 'white '; " vAlign= "middle ">
<TD width= "10% ">
<asp:LinkButton id= "Select " runat= "server " CommandName= "Select "> 选中 </asp:LinkButton>
</TD>
<TD width= "20% ">
<DIV style= "FONT-SIZE: 9pt; FONT-FAMILY: 宋体 " align= "left ">
<asp:Label id= "lblYhdm " Runat= "server ">
<%#DataBinder.Eval(Container.DataItem, "yhdm ")%>
</asp:Label> </DIV>
</TD>
<TD width= "20% ">
<DIV style= "FONT-SIZE: 9pt; FONT-FAMILY: 宋体 " align= "left ">
<asp:Label id= "lblYhbs " Runat= "server ">
<%#DataBinder.Eval(Container.DataItem, "yhbs ")%>
</asp:Label>
</DIV>
</TD>
<TD width= "30% ">
<DIV style= "FONT-SIZE: 9pt; FONT-FAMILY: 宋体 " align= "left ">
<asp:Label id= "lblYhmc " Runat= "server ">
<%#DataBinder.Eval(Container.DataItem, "yhmc ")%>
</asp:Label>
</DIV>
</TD>
<TD width= "20% ">
<DIV style= "FONT-SIZE: 9pt; FONT-FAMILY: 宋体 " align= "left ">
<asp:Label id= "lblYhjc " Runat= "server ">
<%#DataBinder.Eval(Container.DataItem, "yhjc ")%>
</asp:Label>
</DIV>
</TD>
</TR>
</TABLE>
/ItemTemplate>
[解决办法]
沙发,帮忙顶,下班了
[解决办法]
最好用别用用DataList事件,用行事件或者注册控件事件,最好
[解决办法]
<asp:LinkButton id= "Select " CommandArgument= "123 " runat= "server " CommandName= "Select "> 选中 </asp:LinkButton>
[解决办法]
private void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if(e.CommandName == "select ")
{
DataList1.SelectedIndex = e.Item.ItemIndex;
Response.Write(((Label)e.Item.FindControl( "lblYhmc ")).Text)
}
BindDataList(); //调用重新绑定数据的方法
}
[解决办法]
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e) { if (e.CommandName == "Select ") { Response.Write(e.CommandArgument+ "***** "); } }
[解决办法]
来者也
[解决办法]
下班了。帮顶一下。
[解决办法]
最好用js遍历,网上有很多的
[解决办法]
来了
[解决办法]
就顶一下啦
[解决办法]
贴你写的代码
[解决办法]
可还是不行,用Response.Write()输出时没有值.
==========
那 ItemCommand 执行了没有?
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "Select ")
{
Label lbl = e.Item.FindControl( "lblYhdm ") as Label;
Response.Write(lbl == nul ? "没找到 Label " : lbl.Text);
}
}
[解决办法]
就你目前的代码看不出来问题