How to run a function in GridView's SelectedIndexChanged Event

This is a discussion on How to run a function in GridView's SelectedIndexChanged Event within the C# Programming forums, part of the General Programming Boards category; hi guys on my project ( c# asp.net ) i used a gridview to list the students with their numbers, ...

  1. #1
    Registered User Aga^^'s Avatar
    Join Date
    Aug 2008
    Posts
    71

    Exclamation How to run a function in GridView's SelectedIndexChanged Event

    hi guys on my project ( c# asp.net ) i used a gridview to list the students with their numbers, names, surnames, gpa s, if they assigned on a project, project advisor name,project advisor surname.

    Every row has a Assign button. When i clicked the assign button students will be assigned a project with their gpa. The assign function is ready. It is working on a single command button but when i used it in the gridview not. How can i do that?

    my code is below

    Code:
        public void BindDataGrid()
        {
            DataTable dtPro = DBCodes.DataGetir("SELECT * FROM student");
            gvList.DataSource = dtPro;
            gvList.DataBind();
        }
    
        protected void gvList_SelectedIndexChanged(object sender, EventArgs e)
        {
            AssignLevel1();
            BindDataGrid();
    
            for (int i = 0; i < gvList.Rows.Count; i++)
            {
                GridViewRow row = gvList.SelectedRow;
                if (row.Cells[4].ToString() == "1")
                {
                    row.Cells[7].Visible = false;
                }
            }
        }
    thanks..

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,578
    The event that is being raised when you click that button inside the gridview is the GridView.RowCommand event. That's where you want to put your code, or more likely from where you wish to call it.

    There may come a time when you may wish to have more than one field with a button. When you susbcribe to that event via the Designer you will notice (although the link above also provides the event signature) that a GridViewCommandEventArgs object is passed. You can use this object to identify which button inside the row was pressed.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    Incidentally there is a much better gridview control available at codeguru if you are allowed to use 3rd party controls.

  4. #4
    Registered User Aga^^'s Avatar
    Join Date
    Aug 2008
    Posts
    71
    Thanks guys for your answers, mario's information helped me, thanks again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 07:54 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. Replies: 5
    Last Post: 02-08-2003, 07:42 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21