在asp.net中的HTML表格中获取控件名称 [英] Fetch Control Name inside HTML table in asp.net

查看:63
本文介绍了在asp.net中的HTML表格中获取控件名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我如何获取asp.net中html表中控件的名称。



此操作应在c#编码内完成,而不是在Html代码或javascript中完成。





谢谢

Rajeshkumar

解决方案

你好,



如果你试图找到的控件在HTML表格中是服务器端控件,意思是在其中有runat =server属性,然后你就可以通过他们的ID在CodeBehind中访问它们。



如果它们不是服务器控件,并且您不确定表中的行数和每行中的单元格数,您可以遍历行的行和单元格,如下所示:



  foreach (HtmlTableRow行 in  SDTable1.Rows)
{
foreach (HtmlTableCell cell in row.Cells)
{
ControlCollection cc = cell.Controls;
if (cc!= null && cc [ 0 ]!= null
{
// 用它做点什么。
}
}
}

如果你确定行和单元格的数量,简而言之就是表格内容。你可以这样做:

控制ctrl = SDTable1.Rows [ 0 ]。单元格[ 0 ]。控件[ 0 ]; 





希望它有所帮助,让我知道它是怎么回事。



祝你好运。



Azee ...






如果控件未标记为

 runat =server

你将无法在服务器端访问它。



问候,

Greg


Hi,

How can i fetch the name of controls inside the html table in asp.net.

This operation should be done inside in c# coding , not in Html code or javascript.


Thanks
Rajeshkumar

解决方案

Hello there,

If the controls that you are trying to find inside the HTML Table are Server side controls, meaning have runat="server" attribute in them then you'll be able to access them in the CodeBehind just by their ID.

If they are not Server Controls, and you are not certain about the number of Rows in the Table and number of cells in each row, you could traverse through the Rows and Cells of Rows like this:

foreach(HtmlTableRow row in SDTable1.Rows)
            {
                foreach(HtmlTableCell cell in row.Cells)
                {
                    ControlCollection cc =  cell.Controls;
                    if (cc != null && cc[0] != null)
                    { 
                        //Do something with it.
                    }
                }
            }

and if you are certain about the number of rows and cells, in short the Table content. you can do this:

Control ctrl = SDTable1.Rows[0].Cells[0].Controls[0];



Hope it helps, let me know how it goes.

Good luck.

Azee...


Hi,

If the control is not marked as

runat="server"

you will not be able to access it on serverside.

Regards,
Greg


这篇关于在asp.net中的HTML表格中获取控件名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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