none
ADO.NET RRS feed

  • 问题

  •         protected void Button1_Click(object sender, EventArgs e)
            {
                Students student = new Students();
                
                DataSet ds = student.QueryStudent();
                table(ds);

            }

          public void table(DataSet ds)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("<table>");
                int i = 1;
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    //tr
                    sb.Append("<tr>");
                    //td\\
                     string str1 = dr["id"].ToString();
                        sb.Append("<td>"+i+"</td>");
                 
                        sb.Append("<td><a href=\"Delete.aspx?id="+str1+"\">delete</td>");
                        sb.Append("<td><a href=\"updata.aspx?id=" + str1 + "\">updata</td>");
                   
                   
                       
                        sb.Append("<td>"+str1+"</td>");

                   
                    //td
                    string str2 = dr["name"].ToString();
                    sb.Append("<td>" +str2+ "</td>");
                   
                    i++;
                    //end tr

                }

                sb.Append("</table>");
                this.Label2.Text = sb.ToString();
               
              
            
            }

    找哥哥姐姐帮忙逐条加个注释 让小弟理解下  还没入门  可工作需要  谢谢各位了...




    • 已编辑 易帆 2012年5月21日 9:20
    2012年5月21日 8:42

答案

  • protected void Button1_Click(object sender, EventArgs e)
             {
       
                 Students student = new Students();  //实例化一个Student类
                 
                DataSet ds = student.QueryStudent();  //QueryStudent是student类中定义的一个方法   
                 table(ds);  //调用table方法,将ds作为参数传入
     
            }
     
     
          public void table(DataSet ds)  //此方法为将传入的dataset中的数据以字符串拼接形式拼接出一个html,StringBuilder的Append方法为字符串拼接
             {  
                 StringBuilder sb = new StringBuilder();  //实例化一个StringBuilder
                 sb.Append("<table>");
                 int i = 1;
                 foreach (DataRow dr in ds.Tables[0].Rows)
                 {
                    //tr
                     sb.Append("<tr>");
                     //td\\
                      string str1 = dr["id"].ToString();
                         sb.Append("<td>"+i+"</td>");
                  
                        sb.Append("<td><a href=\"Delete.aspx?id="+str1+"\">delete</td>");
                         sb.Append("<td><a href=\"updata.aspx?id=" + str1 + "\">updata</td>");
                    
                   
                       
                        sb.Append("<td>"+str1+"</td>");
     
                   
                    //td
                     string str2 = dr["name"].ToString();
                     sb.Append("<td>" +str2+ "</td>");
                    
                    i++;
                     //end tr
     
                }
     
                sb.Append("</table>");
                 this.Label2.Text = sb.ToString();
                
              
            
            }

    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    2012年5月22日 6:01
    版主