跨页面实现多选

这篇博客详细介绍了如何在ASP.NET环境中实现跨页面的多选功能。内容包括使用.cs文件进行数据绑定,并在页面中利用JavaScript进行交互操作,将JavaScript代码放置在页面底部以确保正确执行。
摘要由CSDN通过智能技术生成
< form id = " form1 "  runat = " server " >
        
< asp:GridView ID = " GridView1 "  runat = " server "  AutoGenerateColumns = " False "  DataSourceID = " ObjectDataSource1 "  AllowPaging = " True "  OnRowDataBound = " GridView1_RowDataBound " >
            
< Columns >
                
< asp:BoundField DataField = " STATIONID "  HeaderText = " STATIONID "  SortExpression = " STATIONID "   />
                
< asp:TemplateField >
                    
< ItemTemplate >
                     
                        
< asp:CheckBox ID = " chkSelect "  runat = " server "  onclick = " checkbox_onchange() " />
                    
</ ItemTemplate >
                
                
</ asp:TemplateField >
                
< asp:BoundField DataField = " STATIONNAME "  HeaderText = " STATIONNAME "  SortExpression = " STATIONNAME "   />
                
< asp:BoundField DataField = " SECONDNAME "  HeaderText = " SECONDNAME "  SortExpression = " SECONDNAME "   />
                
< asp:BoundField DataField = " THIRDNAME "  HeaderText = " THIRDNAME "  SortExpression = " THIRDNAME "   />
                
< asp:BoundField DataField = " ALLROAD "  HeaderText = " ALLROAD "  SortExpression = " ALLROAD "   />
            
</ Columns >
        
</ asp:GridView >
        
< asp:ObjectDataSource ID = " ObjectDataSource1 "  runat = " server "  SelectMethod = " GetAllList "
            TypeName
= " BusManage.BLL.BusStation " ></ asp:ObjectDataSource >
            
< input id = " eleName "   readonly
type
= " text "  size = " 53 "  runat = " server " >   < input id = " eleValue "  type = " hidden "  runat = " server " >
    
</ form >

 .cs绑定

if (e.Item.ItemType  ==  ListItemType.Item  ||  e.Item.ItemType  ==  ListItemType.AlternatingItem)
    
{
        
if(HdnSelectedValues.Value.IndexOf(((Literal)e.Item.Cells[1].FindControl("TitleShow")).Text) >= 0 )
        
{
            HtmlInputCheckBox ChkSelected 
= (HtmlInputCheckBox)(e.Item.Cells[0].FindControl("ChkSelect"));
            ChkSelected.Checked 
= true;
        }

    }

下面javarscript放页面下方

< script language = " javascript "  type = " text/javascript " >
       
        SetCheckBoxStatus();
        
function  SetCheckBoxStatus()
        
{
            
var tb = document.getElementById("GridView1");
            
var eleValue = document.getElementById("eleValue").value;
             
            
for(var i=1;i<tb.rows.length-1;i++)
            
{
                
var chk =   tb.rows[i].cells[1].firstChild;
                 
                
if(eleValue.indexOf(tb.rows[i].cells[2].innerText+",">-1)
                
{
                    chk.checked 
= true;
                }

                
            }

        }


        
function  checkbox_onchange()
        
         
{
              
var tb = document.getElementById("GridView1");
            
var eleValue = document.getElementById("eleValue");
             
            
for(var i=1;i<tb.rows.length-1;i++)
            
{
                
var chk =   tb.rows[i].cells[1].firstChild;
                
var id  =   tb.rows[i].cells[2].innerText; 
                eleValue.value 
= eleValue.value.replace(id+ ",","");
                
if(chk.checked)
                
{
                     eleValue.value 
= eleValue.value + id+ ",";
                }
 
                
            }

           
       
        }


    
</ script >

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值