?
Solved

VB Programer Trying to Learn some C#

Posted on 2009-04-22
9
Medium Priority
?
384 Views
Last Modified: 2012-05-06
I have developed several Web Applications and generally develop using VB.NET.  I'm trying to help a friend but she codes in C# .  I wrote and converted some existing code that I wrote in VB but have a few errors and I really don't have the time to research the resolution. If one of you could look at the code and educate me on what syntactical changes I need to make, I'll learn a little C# and you'll earn 500 points.  
The issues are as follows:
In the Page_Load section the line
strFullUserName = Request.ServerVariables["LOGON_USER"].ToLower;
Gives an error- Cannot convert method group 'ToLower' to non-delegate type 'string'

And the line
if (Strings.InStr(strFullUserName, "domain") == 0)
Gives an error- The name 'Strings' does not exist in the current context

And in the SingleSelect routine (which is called from a button in a gridview)
the line  SelectedUserID = gvSearchResults.DataKeys _  (gvSearchResults.SelectedIndex).Value.ToString;

Gives an error 'System.Web.UI.WebControls.GridView.DataKeys' is a 'property' but is used like a 'method'




protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
 
            string strUserID = null;
            string strFullUserName = null;
 
            strFullUserName = Request.ServerVariables["LOGON_USER"].ToLower;
 
            Strings;
 
            if (Strings.InStr(strFullUserName, "domain") == 0)
            {
                strUserID = strFullUserName;
            }
            else
            {
                strUserID = strFullUserName.Substring(strFullUserName.IndexOf("\\") + 1);
            }
            if (strUserID.Substring(0, 1) != "u" & strUserID.Substring(0, 1) != "n")
            {
                if (string.IsNullOrEmpty(Request.ServerVariables["uid"].ToUpper))
                {
                    Response.Redirect("Userid.aspx");
                }
                else
                {
                    strUserID = Request.ServerVariables["uid"].ToUpper;
                }
            }
 
            ResultsPanel.Visible = false;
            SearchPanel.Visible = false;
        } 
 
    }
 
 
    protected void SingleSelect(object sender, System.Web.UI.ImageClickEventArgs e)
    {
        ImageButton ibtn = (ImageButton)sender;
        TableCell tblcell = (TableCell)ibtn.Parent;
        GridViewRow gvrow = (GridViewRow)tblcell.Parent;
        string SelectedUserID = "";
 
        gvSearchResults.SelectedIndex = gvrow.RowIndex;
 
        SelectedUserID = gvSearchResults.DataKeys(gvSearchResults.SelectedIndex).Value.ToString;
        string SelectedName = gvrow.Cells(1).Text;
        txtClientName.Text = SelectedUserID + "-" + SelectedName;
 
        gvSearchResults.SelectedIndex = -1;
 
        ResultsPanel.Visible = false;
 
        SearchPanel.Visible = false;
    }

Open in new window

0
Comment
Question by:11ptMan
  • 6
  • 3
9 Comments
 
LVL 22

Assisted Solution

by:p_davis
p_davis earned 2000 total points
ID: 24205779
strFullUserName = Request.ServerVariables["LOGON_USER"].ToLower();//forgot parenthesis
0
 
LVL 22

Assisted Solution

by:p_davis
p_davis earned 2000 total points
ID: 24205800
if (Strings.InStr(strFullUserName, "domain") == 0)//what exactly is Strings?

what are you trying to do compare? see if the string is contained

containing is

strFullUserName.Contains("domain")// boolean
strFullUserName.CompareTo("domain") == 0// boolean as well but the original function returns an int.
0
 
LVL 22

Assisted Solution

by:p_davis
p_davis earned 2000 total points
ID: 24205810
gvSearchResults.DataKeys(gvSearchResults.SelectedIndex).Value.ToString();//again forgot the parenthesis
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:11ptMan
ID: 24206218
p davis

There are no () to remove. That was one of the first things I tried but the two lines read
strFullUserName = Request.ServerVariables["LOGON_USER"].ToLower;
and
SelectedUserID = gvSearchResults.DataKeys(gvSearchResults.SelectedIndex).Value.ToString;
and both still give their respective errors.

One the second point yes,  Contains is what I was looking for if the string contains the domain I want to remove it and return just the username.  I've corrected that - thank you.  
0
 
LVL 22

Assisted Solution

by:p_davis
p_davis earned 2000 total points
ID: 24206414
you need to add them
0
 

Author Comment

by:11ptMan
ID: 24206431
p davis

I reread your note and now see that what you were saying it that I forgot the () and needed to add them to my code. I did but still get the same error
'System.Web.UI.WebControls.GridView.DataKeys' is a 'property' but is used like a 'method'      C:\Projects\PDS\WEB\c_lookup.aspx.cs      76      42      C:\...\WEB\

0
 
LVL 22

Accepted Solution

by:
p_davis earned 2000 total points
ID: 24207117
SelectedUserID = gvSearchResults.DataKeys(gvSearchResults.SelectedIndex).Value.ToString;//indexes in c# need brackets


SelectedUserID = gvSearchResults.DataKeys[gvSearchResults.SelectedIndex].Value.ToString();//corrected
0
 

Author Closing Comment

by:11ptMan
ID: 31573319
P davis, Thank you I apologize for my not reading closely enough your first responses.. I didn't quite get my response sent before you had replied. But I should have read more closely before responding.  Your assistance helped me resolve much more than the three issues I presented here. While no expert I have expanded my understanding a little further today.
0
 
LVL 22

Expert Comment

by:p_davis
ID: 24208889
not a problem -- glad that you felt like you walked away with something more than just the answer.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Integration Management Part 2
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question