简体   繁体   中英

How to get the cell index of textbox in my gridview

How to get the cell index of textbox in my gridview ?

My code :

protected void txt_1_TextChanged(object sender, EventArgs e)
{
     int progSer = int.Parse(Session["prog"].ToString());
     RadNumericTextBox txt = (RadNumericTextBox)sender;

     GridViewRow r = (GridViewRow)txt.NamingContainer;
     //now i want to get the cell index of my fired textbox ,say this text box is in the second column so i want to get index 2
}

You could use TableCellCollection.GetCellIndex and a loop to find the cell of the TextBox :

TableCell cell = null;
Control parent = txt;
while ((parent = parent.Parent) != null && cell == null)
    cell = parent as TableCell;
int indexOfTextBoxCell = -1;
if (cell != null)
    indexOfTextBoxCell = r.Cells.GetCellIndex(cell);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM