Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > For Steven Cheng

Reply
Thread Tools

For Steven Cheng

 
 
Paul
Guest
Posts: n/a
 
      01-10-2004
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> <aspropDownList
ID="lstGender" OnLoad="lstGender_Load" Runat="server">
<asp:ListItem Value="male">Male</asp:ListItem>
<asp:ListItem Value="female">Female</asp:ListItem>
</aspropDownList>
</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();
}



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VS 2005 & Web User Controls -for Steven Cheng adiel_g@hotmail.com ASP .Net Building Controls 0 06-13-2006 03:39 PM
HEXUS.interviews :: Godfrey Cheng of ATI - Avivo and vide... Silverstrand Front Page News 0 10-19-2005 10:02 PM
DataGrid (fao Steven Cheng) Terry Holland ASP .Net Web Controls 3 08-15-2005 07:04 AM
Steven Brehm m1k30rz Case Modding 5 06-27-2005 03:03 PM
Additional Repeater questions for Steven Cheng Mark ASP .Net 2 01-28-2004 11:25 AM



Advertisments