You can utilize Template Fields / Columns to do just that. Define both of
your controls inside the template:
<asp:TemplateField HeaderStyle-Width="20px">
<ItemTemplate>
<asp:DropDownList id="ddl" runat="server" />
<asp:CheckBox id="chk" runat="server" />
</ItemTemplate>
</asp:TemplateField>
and then make one or another invisible, based on your requirements:
private void grd_RowCreated(object sender, GridViewRowEventArgs e)
{
GridViewRow row = e.Row;
if (row.RowType == DataControlRowType.DataRow)
{
TableCell templateCell = row.Cells[_TEMPLATE_COLUMN_INDEX];
if (_ddlControlIndex == -1)
{
_ddlControlIndex = Ctls.GetCellControlIndex(templateCell ,
typeof(DropDownList));
_chkControlIndex = Ctls.GetCellControlIndex(templateCell ,
typeof(CheckBox));
}
((DropDownList)templateCell .Controls[_ddlControlIndex]).Visible =
getDropDownVisibleLogic();
((CheckBox)templateCell .Controls[_chkControlIndex]).Visible =
getCheckBoxVisibleLogic();
}
}
HTH
"yo**@nobhillsoft.com" wrote:
Hi,
i got a grid on an asp.net (2.0) page . i want, in a certain field,
for certain rows to show a combobox, but in other cases show a
checkbox (basically, if i got 1 record or less to show in the combo, i
want just a checkbox) anybody has any idea how it can be done? (best
if anybody knows some article about it, with code snippet of some
sort... vb or c#, doesnt matter)
thanks!
Jonathan