如何获取表中动态创建的标签参数 [英] How to get parameter of label dynamically created in table

查看:87
本文介绍了如何获取表中动态创建的标签参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从标签控制中获取分配数据库值的参数.我使用超链接转到另一页并查看该标签的数据库内容,但是我无法做到这一点,请在下面的代码中帮我以下忙

hi i want take parameter from label control which assigned database value.i used hyperlink to go to another page and view the database content of that label but i am not able to do that please help me below is following code

protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection();
        con.ConnectionString = ConfigurationManager.ConnectionStrings["ConnStringDb1"].ConnectionString;
        SqlCommand cmd = new SqlCommand("select page_name from content", con);
        DataTable dt = new DataTable();
        SqlDataAdapter ad = new SqlDataAdapter();

        ad.SelectCommand = cmd;
        ad.Fill(dt);
      foreach(DataRow dr in dt.Rows)  
      {
           
          Table tb = new Table();
          tb.CellSpacing = 20;
          
          TableRow tr = new TableRow();  
          foreach (DataColumn dc in dt.Columns)     
          {                    
   TableCell tc = new TableCell();
   TableCell tc1 = new TableCell();           
              Label lb = new Label();
             
              lb.Text = dr[dc].ToString();
              HyperLink hp = new HyperLink();
              hp.Text = "Edit";
              hp.NavigateUrl = "Edit_Home_Page_Content.aspx";
              tc.Controls.Add(lb); 
              tc1.Controls.Add(hp);          
              tr.Cells.Add(tc);
              tr.Cells.Add(tc1);
              tb.Rows.Add(tr);           
              Panel1.Controls.Add(tb);
          }
      }
        ad.Dispose();
        cmd.Dispose(); 
        con.Dispose();  
    }

推荐答案



问题不清楚.

Edit_Home_Page_Content.aspx上,您将编写用于检索数据的代码?您将必须使用查询字符串将id传递到此页面,然后必须编写代码以检索数据或将生成的Datatable保留在会话对象中并使用选定的标签进行查询.

就像
Hi

Question is not clear.

On Edit_Home_Page_Content.aspx you will be writing code for retrieving data ? you will have to pass id using query string to this page and then will have to write code to retrieve data or keep generated Datatable in session object and query it using selected label .

like
hp.NavigateUrl = "Edit_Home_Page_Content.aspx?=" + lb.Text;


并在Edit_Home_Page_Content.aspx


and on Edit_Home_Page_Content.aspx

use dt.select()


检索所需行的方法.

已添加代码标签-LOSMAC [/EDIT]


method to retrive desired row.

Code tags added - LOSMAC[/EDIT]



检查一下.
如何在数据库中保存动态控制值? [ ^ ]
最好的问候
米特瓦里(M.Mitwalli)
Hi ,
Check this .
how to save dynamic control values in database?[^]
Best Regards
M.Mitwalli


这篇关于如何获取表中动态创建的标签参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆