c# - how to get column Index by column name? -


i have datagrid having few columns-

the header of grid hyperlink , setting value @ runtime follows-

string strq1 = "<a href='somepage.aspx?id=1'>gfgytyty<a>"; dtgrid.columns[0].header = strq1;  string strq2 = "<a href='somepage.aspx?id=2'>yhtryrtuyu<a>"; dtgrid.columns[1].header = strq2;  , on... 

it working properly. suppose want index of perticular column of datatgrid name not able it. tried

int  colindex = dtgrid.columns.indexof(dtgrid.columns[strq2]); 

this should return 1 columnindex returning -1,

also, dtgrid.columns[strq2] giving me null value.

what doing wrong here?

try use linq firstordefault object first , use .indexof(object) :

dtgrid.columns.indexof(dtgrid.columns.firstordefault(c => c.header == strq2)); 

Comments

Popular posts from this blog

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -

javascript - Using jquery append to add option values into a select element not working -

javascript - Restarting Supervisor and effect on FlaskSocketIO -