Selecting specific columns in GridView

Last post 02-17-2009 3:36 PM by NUStudent. 1 replies.

Sort Posts:

  • Selecting specific columns in GridView

    02-17-2009, 2:50 PM
    • Member
      13 point Member
    • NUStudent
    • Member since 05-27-2008, 10:30 AM
    • Posts 54

    Hello Everyone:

    I am working with a data grid view and the enable select is checked.  My problem is that in my database I have a table that has 2 primary keys (It is related to courses in college e.x. "DepartmentID = ACC CourseID = 242-01", (Different From) "DepartmentID = ACC CourseID = 242-02").  Basically when the user selects a row in the gridview, one could be the 242-01 and the other 242-02, the gridview only gives me the value ACC for me to work with in my select statement (WHERE Clause).  I am trying to make it a multiple WHERE statement being SELECT * FROM tblCourses WHERE DepartmentID = "ACC" and CourseID = "242-01".  The only problem is that the Gridview SelectedIndexChanged SelectedValue only returns the ACC part in the gridview. 

    MAIN QUESTION(S):

    Is there a way to specify what column you want to retrieve on a selectedindexchanged event?
    If so, am I doing it right by having it under the SelectIndexChanged event?

     Let me know if that made any kind of sense what so ever:

     Thanks For Your Time:

    -NUSTUDENT

  • Re: Selecting specific columns in GridView

    02-17-2009, 3:36 PM
    Answer
    • Member
      13 point Member
    • NUStudent
    • Member since 05-27-2008, 10:30 AM
    • Posts 54

    Through Further Research I have found the answer to my question:

     

    1    protected void grdCourses_SelectedIndexChanged(object sender, EventArgs e)
    2        {
    3          string a;
    4          GridViewRow row = grdCourses.SelectedRow;
    5          a = row.Cells[2].Text + ".";
    6          test.Text = Convert.ToString(a);
    7         }
    

     

    Thanks for the views:

    -NUSTUDENT

Page 1 of 1 (2 items)