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


            }

     
     

    }

  • 相关阅读:
    Three.js基础探寻六——文字形状与自定义形状
    Three.js基础探寻五——正二十面体、圆环面等
    Three.js基础探寻四——立方体、平面与球体
    Three.js基础探寻三——透视投影照相机
    Three.js基础探寻二——正交投影照相机
    Three.js基础探寻一
    js 基础 函数传值
    jQuery 判断页面元素是否存在的代码
    手机端点解链接有外框的问题
    团队博客冲刺第七天
  • 原文地址:https://www.cnblogs.com/tiger8000/p/1023306.html
Copyright © 2011-2022 走看看