Click here to Skip to main content
15,908,834 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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();  
    }
Posted
Comments
Jim Jos 17-May-12 5:56am    
Please tell me you are able to see the html page with the label and URL next to it? Also tell me what is that panel1 (is it a frame or name of webform)

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
C#
hp.NavigateUrl = "Edit_Home_Page_Content.aspx?=" + lb.Text;

and on Edit_Home_Page_Content.aspx
C#
use dt.select()

method to retrive desired row.

[EDIT]Code tags added - LOSMAC[/EDIT]
 
Share this answer
 
v2
Hi ,
Check this .
how to save dynamic control values in database?[^]
Best Regards
M.Mitwalli
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900