Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

C# help

Options
  • 27-01-2008 6:29pm
    #1
    Registered Users Posts: 325 ✭✭


    Hi All

    A question here about a part of my prj - I'm using C#, Visual Studios 2005 and MySQL.

    I have designed a website that has a number of pages representing different Student Accommodation Complexes and than a page with a number of radio buttons for a rating system.

    What I need is where if someone is on one Student Complex page and they choose the rating page than when they choose their ratings and click save it saves to that Student Complexes table in the DB.

    I have no idea where I'm suppose to do in order to get this to work - could someone please set me on the right path?


Comments

  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    Why don't you send the Student Complex ID along in the link to the rating page.

    <a href="rating.php?studentComplex={ID}"><img src="mybutton.jpg" /></a>

    Then on the rating page simply grab this. In PHP this would be done by accessing the $_GET[] array, i'm sure it similar the way you are doing it.

    I take it - this is what you are asking about.

    Donal


  • Closed Accounts Posts: 5,284 ✭✭✭pwd


    Read up about the detailsview component in asp.net. It's a very handy data access component for editing and inserting records to a database. I think that would suit your needs.
    You should also read about the gridview component. This is a grid listing different records, and users can edit records from it too. It is difficult to insert records using a gridview though.

    Am I right in thinking the user rates a number of different aspects of the accommodation?


  • Registered Users Posts: 2,790 ✭✭✭John_Mc


    I'm pretty sure the ASP.net 2.0 AJAX toolkit comes with a rating system in the examples, so could be well worth checking it out


  • Registered Users Posts: 325 ✭✭doyler442


    Cheers for the help lads

    Yes they will be voting on a number of different aspects - I have that side working all I need is a way so that depending on which page they use to get to the Rating Page, it will than know to save to that pages Table.

    This is very confusing so heres a little example:

    There on a page called "Town Hall" and theres a button there that they click called "Rate This Accommodation".

    This than brings them to the "Rating" page, they choose there ratings for the different things, than they click the "Save" button.

    I need this to than save into the "Town Hall" table.

    Than if someone was on the "Central Accom" page they go through the same steps as above but when they click save I need it to save it into the "Central Accom" table.


  • Closed Accounts Posts: 5,284 ✭✭✭pwd


    yes use a detailsview.


  • Advertisement
  • Registered Users Posts: 2,790 ✭✭✭John_Mc


    doyler442 wrote: »
    Cheers for the help lads


    There on a page called "Town Hall" and theres a button there that they click called "Rate This Accommodation".

    This than brings them to the "Rating" page, they choose there ratings for the different things, than they click the "Save" button.

    The "Rate this Accomodation" button should pass the Town Hall ID to the Ratings page using a Query string.

    E.G "SubmitRating.aspx?ComplexID=" & ComplexID

    Then on the Ratings page, you can retrieve it easily by using ComplexID=request.querystring("ComplexID")


  • Registered Users Posts: 325 ✭✭doyler442


    Cheers for the info John


    I've been looking up about these Query Strings.

    Seems like they could work but the examples that I have found haven't been very good.

    Could you perhaps explain a bit more such as where exactly am i suppose to put the "SubmitRating.aspx?ComplexID=" & ComplexID - is this in the code where the button is place or when the button is clicked
    Also can I change the ComplexID to whatever I want.

    I'm also stuck as to where I should put ComplexID=request.querystring("ComplexID") - not sure where in the Ratings page it should go


  • Registered Users Posts: 2,790 ✭✭✭John_Mc


    doyler442 wrote: »
    Cheers for the info John


    I've been looking up about these Query Strings.

    Seems like they could work but the examples that I have found haven't been very good.

    Could you perhaps explain a bit more such as where exactly am i suppose to put the "SubmitRating.aspx?ComplexID=" & ComplexID - is this in the code where the button is place or when the button is clicked
    Also can I change the ComplexID to whatever I want.

    I'm also stuck as to where I should put ComplexID=request.querystring("ComplexID") - not sure where in the Ratings page it should go

    A query string is just a way to pass data from one page to another through a URL. (Obviously, this data is not security related as it will be visible in the address bar)

    Your event in this case is the button click. In the code for that , create a variable call ComplexID or whatever and assign a value to it which you can use to identify the attribute on the other page.

    Now you want to redirect to the other page using:

    response.redirect("SubmitRating.aspx?ComplexID=" & ComplexID)

    You're basically concatenating the ComplexID onto the end of the string. If you want to pass more than one value you use the '&' symbol after each value. So you could also use:

    response.redirect("SubmitRating.aspx?ComplexID=" & ComplexID & "&AnotherVariable=" & AnotherVariable)

    On the other page, in the Page_Load function you can retrieve these values by using:

    ComplexID=request.querystring("ComplexID")
    AnotherVariable=request.querystring("AnotherVariable")

    So now you have the data you need to perform the task. Note that you can get the QueryString value in any function - it doesn't have to be page load.

    Hope this helps


  • Registered Users Posts: 325 ✭✭doyler442


    Cheers for this help - I really appreciate it.

    I am however still having just a small bit of difficulty:

    I just said I'd use the names you gave me just to see if I could get it working but when I click play I get 3 error messages

    Two say "The name ComplexID does not exist in the current context" and the other says
    "'System.Web.HttpRequest.QueryString' is a 'property' but is used like a 'method' .

    Any ideas how I could get passed this? Sorry if these are stupid questions


  • Registered Users Posts: 2,790 ✭✭✭John_Mc


    doyler442 wrote: »
    Cheers for this help - I really appreciate it.

    I am however still having just a small bit of difficulty:

    I just said I'd use the names you gave me just to see if I could get it working but when I click play I get 3 error messages

    Two say "The name ComplexID does not exist in the current context" and the other says
    "'System.Web.HttpRequest.QueryString' is a 'property' but is used like a 'method' .

    Any ideas how I could get passed this? Sorry if these are stupid questions

    The QueryString error is most likely coming from incorrectly using the = as an addition rather than assignment. Forgive me but I really only code in VB

    In C# you need to use == when assigning a value to a variable

    As for the ComplexID error, I'll need to see your code for the page giving the error. Just the segments referencing ComplexID will do


  • Advertisement
  • Registered Users Posts: 325 ✭✭doyler442


    Right - I tried putting in the ==, shouldve noticed this myself but it still doesnt work.

    As for the ComplexID error here is the code:

    protected void Button1_Click(object sender, EventArgs e)
    {
    Response.Redirect("Rate.aspx?ComplexID=" & ComplexID);

    }

    AND

    protected void Page_Load(object sender, EventArgs e)
    {
    ComplexID = Request.QueryString("ComplexID");
    }


  • Closed Accounts Posts: 52 ✭✭zardette


    Concatenating Strings in c# use the + sign

    http://en.csharp-online.net/Manipulating_Strings_in_CSharp%E2%80%94Concatenating_Strings

    "In C# you need to use == when assigning a value to a variable"

    thats for a comparision not an assignment but I think you just got them mixup ...

    oh and where are you declaring your variables .. make sure that your contextID is not a a local var.

    here is an example

    private void cmdGo_Click(object sender, System.EventArgs e)
    {
    if (lstItems.SelectedIndex == -1)
    {
    lblError.Text = "You must select an item.";
    }
    else
    {
    string url = "QueryStringRecipient.aspx?";
    url += "Item=" + lstItems.SelectedItem.Text;
    url += "&" + "Mode=" + chkDetails.Checked.ToString();
    //note the second and subsequent arguments need to be preceeded with a & sign
    Response.Redirect(url);
    }

    }


  • Registered Users Posts: 2,790 ✭✭✭John_Mc


    doyler442 wrote: »
    Right - I tried putting in the ==, shouldve noticed this myself but it still doesnt work.

    As for the ComplexID error here is the code:

    protected void Button1_Click(object sender, EventArgs e)
    {
    Response.Redirect("Rate.aspx?ComplexID=" & ComplexID);

    }

    Think about this for a moment... ComplexID is a variable. It therefore needs to be created and then a value assigned to it before using it.

    int complexID =0;

    I presume you have a table in the DB which stores the apartment blocks? If so, you probably have an integer primary key which uniquely identifies each row. You should assign this integer value to ComplexID and then perform the Response.Redirect
    doyler442 wrote: »

    AND

    protected void Page_Load(object sender, EventArgs e)
    {
    ComplexID = Request.QueryString("ComplexID");
    }

    You need to declare the variable ComplexID before trying to assign a value to it.

    Now you can lookup the database using ComplexID and display information on the relevant apartment block. Or you can update the record in the DB with the new submitted rating using the ComplexID


  • Registered Users Posts: 2,790 ✭✭✭John_Mc


    zardette wrote: »
    Concatenating Strings in c# use the + sign

    http://en.csharp-online.net/Manipulating_Strings_in_CSharp%E2%80%94Concatenating_Strings

    "In C# you need to use == when assigning a value to a variable"

    thats for a comparision not an assignment but I think you just got them mixup ...

    Yep, sorry about that! So used to VB.net at this stage


  • Registered Users Posts: 325 ✭✭doyler442


    Rite this is starting to drive me mad :rolleyes:. This is what I have and I'm still getting
    "'System.Web.HttpRequest.QueryString' is a 'property' but is used like a 'method'

    public partial class LancesterHall : System.Web.UI.Page
    {
    int ComplexID = 5;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnRate_Click(object sender, EventArgs e)
    {
    Response.Redirect("Rate.aspx?ComplexID=" & ComplexID);

    }
    }

    AND

    public partial class Rate : System.Web.UI.Page
    {

    OdbcConnection myConn;

    protected void Page_Load(object sender, EventArgs e)
    {
    ComplexID = Request.QueryString("ComplexID");
    }

    I'm also getting an error message of: Operator '&' cannot be applied to operands of type 'string' and 'int'


  • Registered Users Posts: 2,790 ✭✭✭John_Mc


    Try this:

    Request.QueryString["ComplexID"]

    You may need to convert the ComplexID into a string to perform the concatenation. Try & CStr(ComplexID)

    I'm basing this on my knowledge of VB.net so if you get messages from either try googling it


  • Registered Users Posts: 325 ✭✭doyler442


    Hi Again

    Well I managed to get that working, cheers for all your help.

    Would i be able to annoy you with something else now


    Now that I have this working and I have the connection to my DB how do I start setting it up to decide which table to enter the data in


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    I would have just used a RadioButtonList control for the rating system and got the selected value on the postback.. very easy really.

    Just set the values, once the user has selected the value and say click rate, use the page_load event and check the value of your radiobuttonlist

    See http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.radiobuttonlist.aspx


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    ^^ What Ginger said.

    Also, if you're getting an error message you don't understand then try cutting and pasting it into your favourite search engine. You're bound to come up with something.


  • Moderators, Science, Health & Environment Moderators Posts: 8,869 Mod ✭✭✭✭mewso


    I really don't like the use of a button to link to the rating page and then using response.redirect. Unecessary. A simple asp hyperlink with the navigateurl property set to the ratings page with the complexid querystring would be better as there is absolutely no need to post back to that page before going to the ratings page.


  • Advertisement
  • Registered Users Posts: 2,790 ✭✭✭John_Mc


    musician wrote: »
    I really don't like the use of a button to link to the rating page and then using response.redirect. Unecessary. A simple asp hyperlink with the navigateurl property set to the ratings page with the complexid querystring would be better as there is absolutely no need to post back to that page before going to the ratings page.

    In fairness, it hardly matters given the lack of complexity that this project seems to have (going on what the OP has already told us). One extra post back, even though unnecessary, is not going to effect server performance.

    I listed both options available and let the OP make his choice.


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Design it as a usercontrol and embed it into the page then.. solves everything


Advertisement