سؤال

I have a gridview I am populating it by creating a datatable filling that table from my database connection then binding the data to my grid. I am not using the autogenerate columns but I am using autogenerate select. Searching through SO I found this suggestion.

    gridview.Columns[index].Visible=false;

when I added this line I get an index out of range exception thrown when i click the button in my web application.

I used that line after I bound my DataTable to the GridView but I want to hide a row to be used for a different purpose so I need to keep that information from my stored proc.

I also tried manually adding the columns with the <columns> option but it just adds the columns on top of the existing ones.

I am a little new to web programming and taking out the autogenerate select is an option but doesn't help me as much as I would have to spend a lot of time learning to recode the select row feature of the table i dont have. Everything I have read so far has dealt with the autogenerate column problem but I am not using it and if the autogenerate select causes the same issue. I might have no choice.

هل كانت مفيدة؟

المحلول

Hiding a row requires binding to the OnRowDataBound event and setting the style.

Check out this answer: Hide a gridView row in asp.net

نصائح أخرى

For this particular problem I did not realize that AutoGenerateColumns was by default set to true. Whether it is by default or because i used AutogenerateSelect control I am not completely sure but my fix was to explicitly set the AutogenerateColumns to False then populate the grid from the columns element in the control. Thank mello for your reply you got me to the answer i needed.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top