Click here to Skip to main content
16,004,647 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;
}
}
Posted
Updated 6-Apr-16 0:38am

1 solution

C#
YourControlObject.GetType()

should return the type of the control.
You can then use it in your conditional statements like-
C#
if(YourControlObject.GetType()==typeof(Button))
{
  //your task
}

Regarding following line of code-
C#
gvchannel.Rows[r.RowIndex].Cells[ix].Controls.GetType().Text = "Y";

You can not set type of control as such.

It would be helpful for us to give more acurate answer if you can explain what is your requirement.

Thanks
 
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