数据库的所有特定列值的动态链接按钮 [英] Dynamic link button for all the specific column values of a database

查看:51
本文介绍了数据库的所有特定列值的动态链接按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我得到的代码如下:

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



在这里,我仅将最后一列(例如"Entry")值用作链接按钮.但是我希望将中间或第一列的值用作链接按钮.我猜想,代码中有微小的变化.

请任何人在这方面给我建议.

问候,



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,

推荐答案

我不确定为什么要提出这种条件,但是这使您无法在文本的最后一行之前创建任何列:
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:
if (j < dt.Columns.Count - 1)      
{        
  tc.InnerText = dt.Rows[i][j].ToString();      
}



如果您注意到,则仅当"j"具有列计数值(即最后一列)时,才会创建链接按钮.

如果要在所有列中链接,只需删除if并让else中的所有代码执行即可.



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.


这篇关于数据库的所有特定列值的动态链接按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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