Click here to Skip to main content
15,892,839 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
In a 3 column asp:GridView, I need the 2nd column to be either a textbox, a dropdownlist, or a range of data(a from x to y) based on the value of the first column.
Is there a way to do that?

What I currently have is a standalone DropDownList. Then based on the selected value, a MultiView is activated. There are three views that can be activated. A plain TextBox, a DropDownList, and then 2 textboxes a From box and a To box for a range of values. I would like to know if it can be done in a GridView.
Posted

1 solution

You can have gridview with 5 columns (where 1st and 3rd are fixed) and second is shown / hidden depending on the value of the first

Your gridview would then look like this:
1st
2nd a) textbox
2nd b) dropdown
2nd c) range
3rd

Then in CellFormatting event you check the value of 1st column and show / hide 2nd appropriately.

Something like this (in CellFormatting event):
C#
DataRowView drv = CType (dgv.Rows[e.RowIndex].DataBoundItem, DataRowView);
dgv.columns["2nda"].Visible = (drv["1st"] == value1);
dgv.columns["2ndb"].Visible = (drv["1st"] == value2);
dgv.columns["2ndc"].Visible = (drv["1st"] == value3);

e.FormattingApplied = True;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900