When I press a button, it will execute the following method.
MyGridView.Columns.RemoveAt(index);
After this, when I try to remove another column in gridview again, the column data using Eval() will be disappeared. (That column is within the gridview and I won't remove it)
Because when you remove Columns,only the UI doesn't show the value of that field;but you still have that column in your bound datasource……So Eval still works well,but no appearing!!!
Because when you remove Columns,only the UI doesn't show the value of that field;but you still have that column in your bound datasource……So Eval still works well,but no appearing!!!
So could you plz tell me how can I solve this problem?? Thx!
lionelsiu
Member
30 Points
38 Posts
[GridView] After RemoveAt() method, the column data using Eval() is disappeared
Apr 12, 2012 12:56 PM|LINK
When I press a button, it will execute the following method.
After this, when I try to remove another column in gridview again, the column data using Eval() will be disappeared. (That column is within the gridview and I won't remove it)
<asp:TemplateField HeaderText="header"> <ItemTemplate> <%# Eval("data") %> </ItemTemplate> </asp:TemplateField>Please tell me why this will happen? How can I fix this bug?? THX!
sam.kumar
Member
62 Points
46 Posts
Re: [GridView] After RemoveAt() method, the column data using Eval() is disappeared
Apr 15, 2012 09:15 AM|LINK
have u confirmed whether u r deleting the correct column ???
if yes then please post you code where you are removing it >>
TimoYang
Contributor
3732 Points
1275 Posts
Re: [GridView] After RemoveAt() method, the column data using Eval() is disappeared
Apr 15, 2012 09:20 AM|LINK
lionelsiu——
Because when you remove Columns,only the UI doesn't show the value of that field;but you still have that column in your bound datasource……So Eval still works well,but no appearing!!!
lionelsiu
Member
30 Points
38 Posts
Re: [GridView] After RemoveAt() method, the column data using Eval() is disappeared
Apr 15, 2012 10:12 AM|LINK
I am sure I delete the correct column. Here are the code I used to remove the column:
bool ColValueExists = false; bool ColItemsExists = false; bool DeletedColValue = false; int ColValueIndex =-1, ColItemsIndex =-1; foreach (DataControlField col in list.Columns) { if (col.HeaderText == "Total Value") { ColValueIndex = list.Columns.IndexOf(col); ColValueExists = true; } if (col.HeaderText == "Total Items") { ColItemsIndex = list.Columns.IndexOf(col); ColItemsExists = true; } } if (!ColValueExists && addlist.Items.FindByValue("TotalValue").Selected) { BoundField TotalValue = new BoundField(); TotalValue.DataField = "TotalValue"; TotalValue.HeaderText = "Total Value"; TotalValue.NullDisplayText = "0"; TotalValue.SortExpression = "TotalValue"; list.Columns.Add(TotalValue); } else if (ColValueExists && !addlist.Items.FindByValue("TotalValue").Selected) { list.Columns.RemoveAt(ColValueIndex); DeletedColValue = true; } if (!ColItemsExists && addlist.Items.FindByValue("TotalItems").Selected) { BoundField TotalItems = new BoundField(); TotalItems.DataField = "TotalItems"; TotalItems.HeaderText = "Total Items"; TotalItems.SortExpression = " TotalItems"; list.Columns.Add(TotalItems); } else if (ColItemsExists && !addlist.Items.FindByValue("TotalItems").Selected) { if (DeletedColValue) ColItemsIndex--; list.Columns.RemoveAt(ColItemsIndex); } list.DataBind();lionelsiu
Member
30 Points
38 Posts
Re: [GridView] After RemoveAt() method, the column data using Eval() is disappeared
Apr 15, 2012 10:12 AM|LINK
So could you plz tell me how can I solve this problem?? Thx!
TimoYang
Contributor
3732 Points
1275 Posts
Re: [GridView] After RemoveAt() method, the column data using Eval() is disappeared
Apr 16, 2012 01:20 AM|LINK
This isn't a REAL problem but just something like you have a duplicated column in your DataTable.