|
|
|
start date: Wed, 15 Aug 2007 02:55:04 -0000,
posted on: microsoft.public.dotnet.framework.aspnet
back
| Thread Index |
|
1
unknown
|
|
2
Sergey Poberezovskiy
|
|
3
unknown
|
any way to change a control inside a grid?
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
Date:Wed, 15 Aug 2007 02:55:04 -0000
Author:
|
RE: any way to change a control inside a grid?
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
"yoni@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
>
>
Date:Tue, 14 Aug 2007 20:48:01 -0700
Author:
|
Re: any way to change a control inside a grid?
On Aug 14, 11:48 pm, Sergey Poberezovskiy
wrote:
> 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
>
>
>
> "y...@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- Hide quoted text -
>
> - Show quoted text -
that worked like magic! thanks very much!
Date:Mon, 20 Aug 2007 02:59:56 -0000
Author:
|
|
|