我可以在gridview单元格中有不同的视图吗? [英] Can I have a different view in a gridview cell?
问题描述
在3列asp:GridView中,我需要第二列是基于第一列值的文本框,下拉列表或一系列数据(从x到y)。
有没有办法做到这一点?
我目前拥有的是一个独立的DropDownList。然后根据所选值激活MultiView。有三种视图可以激活。一个普通的TextBox,一个DropDownList,然后是2个文本框,一个From框和一个To框,表示一系列值。我想知道它是否可以在GridView中完成。
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.
推荐答案
你可以使用5列的gridview(其中第1和第3是固定的),第二个是/隐藏取决于第一个价值
您的gridview将如下所示:
1st
第2个a)文本框
第二个b)下拉菜单
第二个c)范围
第三个
然后在CellFormatting事件中,你检查第一列的值并适当地显示/隐藏第二列。
像这样(在CellFormatting事件中):
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):
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;
这篇关于我可以在gridview单元格中有不同的视图吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!