如何从行和中获取gridview中的控件类型细胞号 [英] How to get control type in gridview from row & cell no

查看:55
本文介绍了如何从行和中获取gridview中的控件类型细胞号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望获得特定行中的控件类型(如Row [0] .cell [2])



如果这将是一个按钮然后在接下来我要求通过该按钮的文本属性显示某些东西



我尝试了什么:



foreach(gvchannel.Rows中的GridViewRow)

{

按钮btn_A1 =(按钮)r.FindControl(btn_A1);

if(cSiteData.stCh [r.RowIndex] .EN)

{

btn_A1.Text =A;

}

其他

btn_A1.Text =;

标签lbl_Ch1 =(标签)r.FindControl(lbl_Ch1) ;

lbl_Ch1.Text = Convert.ToString(r.RowIndex + 1);



Label lbl_Flat1 =(Label)r.FindControl( lbl_Flat1) ;

lbl_Flat1.Text = cSiteData.stCh [r.RowIndex] .flat.ToString();



TextBox txt_PPP1 =(TextBox) r.FindControl(txt_PPP1);

txt_PPP1.Text = cSiteData.stCh [r.RowIndex] .ppp.ToString();





int drGrp = cFunc.AscHex(cSiteData.stCh [r.RowIndex] .drGroup [0]);

drGrp<< = 4;

drGrp | = cFunc.AscHex(cSiteData.stCh [r.RowIndex] .drGroup [1]);

drGrp<< = 4;

drGrp | = cFunc.AscHex(cSiteData.stCh [r.RowIndex] .drGroup [2]);

drGrp<< = 4;

drGrp | = cFunc.AscHex(cSiteData.stCh [r.RowIndex] .drGroup [3]);

// int ix = dataGridViewCh.Rows [n] .Cells [Dr0]。ColumnIndex;

int ix = 4;



for(int i = 0;我< 16; i ++,ix ++)

{//组组按钮

if((drGrp& 0x0001)== 1)

// dataGridViewCh。行[n]。细胞[ix] .Value =Y;

gvchannel.Rows [r.RowIndex] .Cells [ix] .Controls.GetType()。Text =Y;



其他

//dataGridViewCh.Rows [n]。细胞[ix] .Value =;

gvchannel.Rows [r.RowIndex] .Cells [ix] .Text =;

drGrp>> = 1;

}

}

i want to get control type in a specific row (like Row[0].cell[2])

If This Will be A Button Then In the Next I have A requirement To Display Something through Text Property Of That Button

What I have tried:

foreach(GridViewRow r in gvchannel.Rows)
{
Button btn_A1 = (Button)r.FindControl("btn_A1");
if (cSiteData.stCh[r.RowIndex].EN)
{
btn_A1.Text = "A";
}
else
btn_A1.Text = "";
Label lbl_Ch1 = (Label)r.FindControl("lbl_Ch1");
lbl_Ch1.Text= Convert.ToString(r.RowIndex + 1);

Label lbl_Flat1 = (Label)r.FindControl("lbl_Flat1");
lbl_Flat1.Text= cSiteData.stCh[r.RowIndex].flat.ToString();

TextBox txt_PPP1 = (TextBox)r.FindControl("txt_PPP1");
txt_PPP1.Text= cSiteData.stCh[r.RowIndex].ppp.ToString();


int drGrp = cFunc.AscHex(cSiteData.stCh[r.RowIndex].drGroup[0]);
drGrp <<= 4;
drGrp |= cFunc.AscHex(cSiteData.stCh[r.RowIndex].drGroup[1]);
drGrp <<= 4;
drGrp |= cFunc.AscHex(cSiteData.stCh[r.RowIndex].drGroup[2]);
drGrp <<= 4;
drGrp |= cFunc.AscHex(cSiteData.stCh[r.RowIndex].drGroup[3]);
//int ix = dataGridViewCh.Rows[n].Cells["Dr0"].ColumnIndex;
int ix = 4;

for (int i = 0; i < 16; i++, ix++)
{ // Do Group Buttons
if ((drGrp & 0x0001) == 1)
//dataGridViewCh.Rows[n].Cells[ix].Value = "Y";
gvchannel.Rows[r.RowIndex].Cells[ix].Controls.GetType().Text = "Y";

else
//dataGridViewCh.Rows[n].Cells[ix].Value = "";
gvchannel.Rows[r.RowIndex].Cells[ix].Text = "";
drGrp >>= 1;
}
}

推荐答案

YourControlObject.GetType()



应该返回控件的类型。

然后你可以在条件语句中使用它,比如-


should return the type of the control.
You can then use it in your conditional statements like-

if(YourControlObject.GetType()==typeof(Button))
{
  //your task
}



关于以下代码行 -


Regarding following line of code-

gvchannel.Rows[r.RowIndex].Cells[ix].Controls.GetType().Text = "Y";



您无法设置控制类型如此。



如果你能解释一下你的要求,我们会给出更多精确答案。


谢谢


这篇关于如何从行和中获取gridview中的控件类型细胞号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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