.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Values of Selected Row from a Gridview in TextBox

Posted By:satyapriyanayak       Posted Date: April 01, 2013    Points: 40    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

Values of Selected Row from a Gridview in TextBox
 

Here in this Example we will learn how to get the values of selected row from a Grid view and display the values in textboxes using C# code. We can edit, update, cancel, select, and delete data also.

 

Default.aspx code

 

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>Untitled Page</title>

   

<style type="text/css">

        .style1

        {

            width: 112%;

        }

        .style2

        {

            width: 169px;

        }

    </style>

</head>

<body>

    <form id="form1" runat="server">

    <div style="background-color: #FF9900; width: 356px;">

   

        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

            DataKeyNames="id" Height="264px" onrowediting="GridView1_RowEditing"

            onrowupdating="GridView1_RowUpdating"

            onselectedindexchanged="GridView1_SelectedIndexChanged" Width="379px"

            BackColor="#66CCFF" BorderColor="#FF0066"

            onrowcancelingedit="GridView1_RowCancelingEdit"

            onrowdeleting="GridView1_RowDeleting">

            <Columns>

                <asp:BoundField DataField="id" HeaderText="Id" />

                <asp:BoundField DataField="name" HeaderText="Name" />

                <asp:BoundField DataField="address" HeaderText="Address" />

                <asp:BoundField DataField="salary" HeaderText="Salary" />

                <asp:CommandField ShowEditButton="True" />

                <asp:CommandField ShowSelectButton="True" />

                <asp:CommandField ShowDeleteButton="True" />

 

               

            </Columns>

            <SelectedRowStyle BackColor="#FF66FF" />

        </asp:GridView>

   

        &nbsp;&nbsp;&nbsp;&nbsp;

        <table class="style1" style="background-color: #CCFF99; height: 268px;">

            <tr>

                <td class="style2">

                    ID</td>

                <td>

                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

                </td>

            </tr>

            <tr>

                <td class="style2">

                    Name</td>

                <td>

                    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>



     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend