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

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

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -