zoukankan      html  css  js  c++  java
  • 关于循环 GridView 及 Repeater 中的数据行的问题!


    GridView 中嵌套 Repeater ,显示分级数据:

    在 GridView1 的 GridView1_DataBound 事件中这样写:

     protected void GridView1_DataBound(object sender, EventArgs e)
        {
            
    foreach (GridViewRow row in GridView1.Rows)
            {
                Label LabelID 
    = row.FindControl("Label1"as Label;
                
    string parentID = LabelID.Text.ToString();
                Repeater subRepeater 
    = row.FindControl("Repeater1"as Repeater;
                
    string sql = "select * from CandidateUser where WantPosition = '"+parentID+"' order by UID asc";
                DataSet ds 
    = newdb.CommonDataSet(sql);
                subRepeater.DataSource 
    = ds.Tables[0].DefaultView;
                subRepeater.DataBind();
                
            }

        }

    然后,当点击按钮,提交此页面,需要循环 GridView1 和 Repeater1 中的数据取值,存入数据库,如何取值呢,这样做:
    protected void Button1_Click(object sender, EventArgs e)
    {
      
    foreach (GridViewRow row in GridView1.Rows)
            {
                Label LabelID 
    = row.FindControl("Label1"as Label; //竞聘职位的ID号Label
                parentID = LabelID.Text.ToString();//竞聘职位的ID号


                Repeater subRepeater 
    = row.FindControl("Repeater1"as Repeater;

                
    foreach (RepeaterItem subrow in subRepeater.Items)
                {
                    Label LabelUserID 
    = subrow.FindControl("Label2"as Label;  //竞聘人的身份ID号Label
                    CandidateUserID = LabelUserID.Text.ToString();//竞聘人的身份ID号

                    TextBox txbScore 
    = subrow.FindControl("TextBox1"as TextBox;  //分数 TextBox1
                    CandidateScore = txbScore.Text.ToString();//分数

                    CheckBox ckbGiveUp 
    = subrow.FindControl("CheckBox1"as CheckBox;  //分数 TextBox1
                    if (ckbGiveUp.Checked == true)
                    {
                        giveup 
    = "1";
                    }
                    
    else
                    {
                        giveup 
    = "0";
                    }


                    sql 
    = "insert into VoteTable (PositionID,CandidateUserID,CandidateUserScore,GiveUpVote,WhoSendTheVote) values ('" + parentID + "','" + CandidateUserID + "','" + CandidateScore + "','" + giveup + "','" + getName + "')";
                    newdb.ModifyData(sql);
             
                }


            }

     
     

    }

  • 相关阅读:
    jquery的动画函数animate()讲解一
    用js来实现页面的换肤功能(带cookie记忆)
    Extjs换肤+cookie皮肤记忆功能
    jquery换肤
    bootstrap的alert提示框的关闭后再显示问题
    jquery.cookie中的操作
    CSS中设置margin:0 auto; 水平居中无效的原因分析
    jQuery 遍历 json 方法大全
    jquery.min.map 404 (Not Found)出错的原因及解决办法
    AJAX 跨域请求的解决办法:使用 JSONP获取JSON数据
  • 原文地址:https://www.cnblogs.com/tiger8000/p/1023306.html
Copyright © 2011-2022 走看看