473,409 Members | 2,006 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

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

Aug 15 '07 #1
2 1154
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

Aug 15 '07 #2
On Aug 14, 11:48 pm, Sergey Poberezovskiy
<SergeyPoberezovs...@discussions.microsoft.comwrot e:
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!

Aug 20 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: SteveC | last post by:
In my ASP.NEt codebehind, I declare a public var for a DataGrid. Then in the TextChanged event handler for a TextBox, I create a <div> tag, stuff it inside the form, then instance a DataGrid and...
2
by: Joe Au | last post by:
I first add a grid layout panel control to a web form, then put a data grid inside the panel. When I run the web form, the data grid is filled up but it throws outside the panel control. The panel...
6
by: MattB | last post by:
I have a page header that I made as a user control (ascx) that I drop on every page in my application. The application is an eCommerce application and I have a total for items in the cart on the...
1
by: Roy | last post by:
How is it done? BTW, I'm reposting this here, as the datagrid newsgroup appears functionally comatose... I have a nested datagrid setup. When one updates the child grid using edit, it also...
1
by: Shahid Saleem | last post by:
Dear Members I want to generate a Template using DataList and i want to user Grid control in the item template, is it possible. if yes need some explanation regarding data binding of grid...
7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
1
by: Kiran | last post by:
Hello All, I created a grid, where I register events every time the user changes an existing value inside the grid control. Right now, I am using the event: EVT_GRID_CELL_CHANGE. However, I...
0
by: cmrhema | last post by:
hello I am required to do a custom control(not a user control) with grid inside it. I have just completed a simple custom control. But i have no idea with grid inside it. While surfing through...
2
by: steven | last post by:
i've got a dropDownList that I'm trying to populate from my code behind as follows: uxVehicleColourEdit.DataSource = oDsLookups.Tables; if the dropDown is placed inside a datagrid, i get...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.