Click here to Skip to main content
15,902,024 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
Hi,

How to convert the below to c#:

Public Sub SelectAll2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgDiscountingInvoicesEmpNames.SelectedIndexChanged

EndSub
Posted

You can do it automatically. There are on-line services for this purpose, but you can do it off-line with very good quality to a whole assembly, using open-source product ILSpy. Please see my past answer: Code Interpretation, C# to VB.NET[^].

—SA
 
Share this answer
 
Comments
Baroor 17-Dec-15 1:05am    
When i converted this was the converted method

public void SelectAll(System.Object sender, System.EventArgs e)
{
DataGridItem dgItem = default(DataGridItem);
CheckBox ChkBxItem = default(CheckBox);
if (GvDiscountingInvoices.Rows.Count > 0)
{
if (sender.Checked)
{
foreach (GridViewRow gvrow in GvDiscountingInvoices.Rows)
{
ChkBxItem = (CheckBox)gvrow.FindControl("chkbox");
ChkBxItem.Checked = true;
}
}
else
{
foreach (GridViewRow gvrow in GvDiscountingInvoices.Rows)
{
ChkBxItem = (CheckBox)gvrow.FindControl("chkbox");
ChkBxItem.Checked = false;
}
}
}
else
{
// ''Dim strScript As String = "<script>alert('No Records to select');</script>"
// ''Me.RegisterClientScriptBlock("alertmessage", strScript)
ScriptManager.RegisterStartupScript(Page, this.GetType(), "AlertMessage", "alert('No Records to select');", true);

sender.Checked = false;
}
}

But showing error at sender.Checked, as object does not contain defination.
Sergey Alexandrovich Kryukov 17-Dec-15 1:18am    
Why, why are you showing me this code? I gave you exact recipe on how you can do the translation yourself and fully automatically? Please remove your code (by the way, never write code in comment, write it the body of your questions), and follow my advice. Your code will be translated; I'll guarantee it.
—SA
BillWoodruff 17-Dec-15 2:25am    
Please move this code to your question, and format with CP's code editing facilities.
The method translates as:

public void SelectAll2(System.Object sender, System.EventArgs e)<br />
{<br />
}


In C# the equivalent to VB.Net's 'Handles syntax requires:

A. a valid reference to an instance of an object/class for which the event 'SelectAll2 is defined:

private dgDiscountingInvoicesEmpNames dIENames;

B. wiring-up the EventHandler to the instance

// somewhere in your code:<br />
dIENames = new dgDiscountingInvoicesEmpNames(); <br />
dIENames += SelectAll2;


Note that in VB this valid instance of an object/class exposing the Event is done by instantiating a 'WithEvents variable.
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900