473,322 Members | 1,610 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,322 software developers and data experts.

For Steven Cheng

Hello Steven,
I saw your code for the onLoad event for a dropdownlist
in a datagrid, and that was exactly what I needed for the
problem I had with a checkboxlist.
However, I have one problem that I've been trying to
figure out.
By the way your email address is invalid.

I have multilple rows in the grid. How do I pass the index
of that row to the onload event handler. Here's your code
and mine. The checkbox list have 3 checkbox with values B,
L and D (Breakfast, Lunch, Dinner).

Notice the TODO: in the row index.

My CODE
Public Sub EditServingType_Load(ByVal source As Object,
ByVal e As
EventArgs)
Dim servingType As CheckBoxList = CType(source,
CheckBoxList)

Select Case
CType(CheckDBNull(Me.RestaurantsDataset.Tables(0). Rows
(TODO: INDEX SHOULD GO HERE)("ServingTypeCode")),
String).Trim
Case "B"
servingType.Items(0).Selected = True
Case "L"
servingType.Items(1).Selected = True
Case "D"
servingType.Items(2).Selected = True
Case "BL"
servingType.Items(0).Selected = True
servingType.Items(1).Selected = True
Case "BD"
servingType.Items(0).Selected = True
servingType.Items(2).Selected = True
Case "LD"
servingType.Items(1).Selected = True
servingType.Items(2).Selected = True
Case "BLD"
servingType.Items(0).Selected = True
servingType.Items(1).Selected = True
servingType.Items(2).Selected = True
End Select
End Sub

Your CODE:

You can specify a
"OnLoad" event handler for the DropDownList, for example:
<asp:TemplateColumn> <ItemTemplate>
<%# DataBinder.Eval(Container.DataItem,"gender") %>
</ItemTemplate> <EditItemTemplate> <asp:DropDownList
ID="lstGender" OnLoad="lstGender_Load" Runat="server">
<asp:ListItem Value="male">Male</asp:ListItem>
<asp:ListItem Value="female">Female</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>

Then, implement this handler function("lstGender_Load") in
the Page Class: protected void lstGender_Load(object
source, System.EventArgs e) { DropDownList lstGender =
(DropDownList)source; //get the datasource of the DataGrid
(you should change it to other
//if you don't use DataTAble as the datasource)
DataTable tb = (DataTable)gridTest.DataSource;
DataRow row = tb.Rows[gridTest.EditItemIndex];

if(row["gender"].Equals("male"))
{
lstGender.SelectedIndex = 0;
}
else
{
lstGender.SelectedIndex = 1;
}
}
Then, in the DataGrid's EditCommand event, you just need
to set its
EditItemIndex and rebind the data:

private void gridTest_EditCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
gridTest.EditItemIndex = e.Item.ItemIndex;
gridTest.DataSource = Get_Data();//Get_Data() returns a
DataTable for
testing
gridTest.DataBind();
}

Nov 18 '05 #1
0 730

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

Similar topics

5
by: Daniel | last post by:
Hi, From what I read from the PHP manual, chmod on a Windows platform should have no effect, and that seems totally normal (unless someone on sourceforge has a windows port of that!). I...
5
by: Bhakta Steven | last post by:
Hey one and all, I have a web page I am working on with Dreamweaver and when I load the page from the site in IE I get errors on lines 505, 69, 2, and 1. Can anyone look at it? It is at...
0
by: Philipp Lenssen | last post by:
I've recently been attending an XHTML 2 and XForms tutorial by Chair of HTML and Forms working groups Steven Pemberton. Here are my impressions: XHTML 2 and XForms...
2
by: Mark | last post by:
I am trying to use a Pagable Repeater with checkboxes in ASP.Net, I cannot seem to associate the checkbox with a particular database record so I lose the checked state from page-to-page. Below is...
15
by: Nathan | last post by:
I have an aspx page with a data grid, some textboxes, and an update button. This page also has one html input element with type=file (not inside the data grid and runat=server). The update...
16
by: | last post by:
Hi all, I have a website running on beta 2.0 on server 2003 web sp1 and I keep getting the following error:- Error In:...
2
by: whoopding | last post by:
I would like to find people who have studied this book. I want to see other peoples solutions to the exercises set at the end of each chapter. This is purely so that I can compare others...
4
by: lesperancer | last post by:
it looks like this will save many versions of a relationship window, but based on the fact that the same tables are displayed in the relationship window and it will restore versions of what was...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.