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);
             
                }


            }

     
     

    }

  • 相关阅读:
    Git配置
    第一次作业
    第二次作业
    python目前最好用的IDE——pycharm
    九九乘法表
    python语言的优点和缺点
    Python高效编程的19个技巧
    Python中 filter | map | reduce | lambda的用法
    Python 代码优化常见技巧
    求逆序对
  • 原文地址:https://www.cnblogs.com/tiger8000/p/1023306.html
Copyright © 2011-2022 走看看