Tranlsation from VB, anyone?

G

Google Jenny

Hi, there. Can a kind soul translate this VB fragment into C# for me?



<asp:TemplateColumn><ItemTemplate><asp:CheckBox id=CheckBox1
runat="server" text='<%# DataBinder.Eval(Container, "DataItem.FileName")
%>' checked='<%# DataBinder.Eval(Container, "DataItem.Checked")
%>'></asp:CheckBox><DIV align="right">(pages:<asp:label id=Label1
runat="server" text='<%# DataBinder.Eval(Container, "DataItem.Pages")
%>'></asp:Label>)</DIV></ItemTemplate></asp:TemplateColumn>

When your cells need contols with Event Handlers assigned dynamically,
you can use the Item_DataBound Event in your code module as: (where the
<i>second</i> control in the first cell is a dropdown box)

BEGIN CODE FRAGMENT
*******************************************************
Private Sub myDG_ItemDatabound(ByVal sender As Object, ByVal e As
DataGridItemEventArgs) Handles dgProcedures.ItemDataBound

dim myDropDown as dropdownbox =
directcast(e.item.cells(0).controls(1),dropdownbox)
addHandler myDropDown.SelectedIndexChange, addressof
myDropDownHandler
'rem: the myDropDownHandler should not have a "handles"
statement, but must have the same signature as the
' event hanldler

End Sub

********************************************************

Thanks so much,
Google Jenny
 
M

Morten Wennevik

Hi Google Jenny,

I guess it would be something like

private void myDG_ItemDataBound(object sender, DataGridItemEventArgs e)
{
dropdownbox myDropDown = (dropdownbox)(e.Item.Cells[0].Controls[1]);
myDropDown.SelectedIndexChanged += new EventHandler(myDropDownHandler);
}

You will need to add

dgProcedures.ItemDataBound += new DataGridItemEventHandler(myDG_ItemDataBound);

somewhere, possibly in Page_Load

Not sure what a dropdownbox is, but I suspect it is some kind of custom control.
Note, the code may not be entirely correct as my VB skills are rather dodgy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top