Click here to Skip to main content
15,911,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have got the code as below:

if (dt.Rows.Count > 0)
 {
   lblMsg.Text = "";
   LinkButton lnkButton = new LinkButton();
   for (int i = 0; i < dt.Rows.Count; i++)
   {
     HtmlTableRow tr = new HtmlTableRow();
     for (int j = 0; j < dt.Columns.Count; j++)
    {
      HtmlTableCell tc = new HtmlTableCell();
      tc.Style["width"] = "10%";
      tc.BgColor = "White";
      if (j < dt.Columns.Count - 1)
      {
        tc.InnerText = dt.Rows[i][j].ToString();
      }
      else
      {
          string value = dt.Rows[i][j].ToString();
          if (value == "0")
          {
             tc.InnerText = dt.Rows[i][j].ToString();
          }
          else
          {
            lnkButton = new LinkButton();
            string lnkid = dt.Rows[i][0].ToString();
            lnkButton.ID =lnkid;                                           
            lnkButton.Text = dt.Rows[i][j].ToString();
            lnkButton.Click += new System.EventHandler(this.lnkButton_Click);
            tc.Controls.Add(lnkButton);                                                                        }
        }
           tr.Cells.Add(tc);
       }
         tbRowDetails.Rows.Add(tr);
      }
      tbRowDetails.Visible = true;
         tbDetails.Visible = true;
   }


Here, I am getting only the last column(say,"Entry") values as link button.. But I want a middle or the first column values as link button. I guess, there is a minor change in the code.

Plzzz any one suggest me on this..

Regards,
Posted
Updated 5-Mar-11 0:45am
v4

1 solution

I am not sure why you have put up this condition but this is stopping you from making any column before last as just a text:
C#
if (j < dt.Columns.Count - 1)      
{        
  tc.InnerText = dt.Rows[i][j].ToString();      
}


If you notice, your link buttons are created only when 'j' is having column count value (that would be last column.)

If you want links in all columns, just remove the if and let all the code in else to get executed.
 
Share this answer
 
Comments
Raj.rcr 5-Mar-11 6:48am    
I tried by removing the if statement and did what u suggested, but still i am not able to get the link for the specific column..
Sandeep Mewara 5-Mar-11 6:50am    
I doubt that. It looks simple and should work now. A simple DEBUG can tell you that. Try first, if still unable to then post the new code.
Raj.rcr 5-Mar-11 6:57am    
I tried changing the value instead of zero(0) in the following.
string lnkid = dt.Rows[i][0].ToString();
Please have a look.. Its not working
Sandeep Mewara 5-Mar-11 7:00am    
Dude! I asked something else and you did something else and come back with not working.
Not just it, a simple DEBUG can tell you how the execution is happening and what you need to do.

Sandeep Mewara 5-Mar-11 7:02am    
One more thing, if you are unable to debug or resolve after I told the exact place where the LOGIC is wrong, then I doubt if you have written this code so far.

Copied it from someone?

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