Thursday, August 3, 2017

// // Leave a Comment

How to Select record from Gridview using C#



I this article I am going to explain how to select record from Gridview using C# code.

As previous article, you have to create a new project.

How to create new project with Visual Studio

Watch Video

Also I have explained how to bind data with Gridview

How to bind data with Gridview

Watch Video

Design screen for Bank code and Bank name using Labels and Text Boxes. give them IDs as Bank Code as txtBcode and Bank Name as txtBname



Click on the Gridview and you can see arrow top right. When you click on arrow pop menu will display named as Gridview Tasks.

In that Gridview Task menu, you have to check the Enable Selection.

Then you can see new column added to Gridview and show Select for every row with Blue colour.

Next click on Gridview and go to properties and click Even icon, then you can see all events of Gridview.

From that event list go to SelectIndexChanges and double click. Then SelectIndexChanged event coding window will display and you can write the code as below


protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridViewRow row = GridView1.SelectedRow;
        txtBcode.Text = row.Cells[1].Text;
        txtBname.Text = row.Cells[2].Text;
    }


Run the project and you can see data with Gridview and first column as select. when you click on select link button. selected row bank code and bank name displayed on Bank code textbox and Bank name text box.

Watch Video
















0 comments:

Post a Comment