开发者

Adding new Columns to GridView with a new DataSource

I have a gridview that is loaded from a DataSet, in which most of the fields are generated through templates.

One of them is an Image that changes according to the value that is returned from the dataset. Here is an example:

<asp:TemplateField HeaderText="Attention">
  <ItemTemplate>
    <asp:Image ID="alertFlag" runat="server" ImageUrl='<%开发者_StackOverflow# Eval("alertFlag").ToString().Equals("True") ? "~/Images/Warning-32.png" : "" %>' />
  </ItemTemplate>
</asp:TemplateField>

Now I have a dropdown list, in which, depending on what is chosen, a new request to the database is made, and new columns are added, but the previous ones must stay.

Should I create a new GridView or how should I add new the new columns, keep them hidden, and then show them when the proper event is fired. this includes loading new data from the database and binding to the gridview. And how would I add the condition above programatically?

Thanks.


I would say that you will use the same gridview and have column with visible set to true or false. I will suggest that you have a property in the code behind such as ShowColumnX which will return true or false based on the dropdown value. In the aspx, you will then bind the visible property to that value such as Visible="<%= ShowColumnX %>"

If your existing column is setup to bind value correctly to a field of your data source, then you dont have to do anything different then what you have already done such as rebinding the data source on postback.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜