Popular Posts
Enable edit option in Shutter in Linux sudo apt-get install libgoo-canvas-perl Reference: How To Fix Disabled Edit Option In Shutter in Linux Mint CORS in Asp.net MVC Web API v2 Step 1. Install cors from NeGet Step 2. Enable cors in config using System; using System.Collections.Generic; using System.Linq; using ... DNS SERVER LIST Google 8.8.8.8 8.8.4.4 TWNIC 192.83.166.11 211.72.210.250 HiNet 168.95.1.1 168.95.192.1 Seednet 北區 DNS (台北, 桃園, 新竹, 宜蘭, 花蓮, 苗栗) 139....
Stats
Select row by clicking in a GridView
GridViewSelectRow.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridViewSelectRow.aspx.cs"
    Inherits="GridViewSelectRow" EnableEventValidation="false" %>

<!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>Select row by clicking in a GridView</title>
</head>
<body>
    <form id="form1" runat="server">
    <table border="1">
        <tr>
            <td>
                SELECTED ID
            </td>
            <td>
                <asp:Label ID="sID" runat="server" Text="Label"></asp:Label>
            </td>
        </tr>
        <tr>
            <td>
                SELECTED UNIQUEID
            </td>
            <td>
                <asp:Label ID="sUniqueID" runat="server" Text="Label"></asp:Label>
            </td>
        </tr>
        <tr>
            <td>
                SELECTED PRICE
            </td>
            <td>
                <asp:Label ID="sPrice" runat="server" Text="Label"></asp:Label>
            </td>
        </tr>
        <tr>
            <td>
                SELECTED AMOUNT
            </td>
            <td>
                <asp:Label ID="sAmount" runat="server" Text="Label"></asp:Label>
            </td>
        </tr>
        <tr>
            <td>
                SELECTED CREATEDATE
            </td>
            <td>
                <asp:Label ID="sCreateDate" runat="server" Text="Label"></asp:Label>
            </td>
        </tr>
    </table>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID,UniqueID"
        DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound" OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
        AllowPaging="True">
        <Columns>
            <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
                SortExpression="ID" />
            <asp:BoundField DataField="UniqueID" HeaderText="UniqueID" ReadOnly="True" SortExpression="UniqueID" />
            <asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
            <asp:BoundField DataField="Amount" HeaderText="Amount" SortExpression="Amount" />
            <asp:BoundField DataField="CreateDate" HeaderText="CreateDate" SortExpression="CreateDate" />
        </Columns>
    </asp:GridView>
    <div>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:brucedbConnectionString %>"
            SelectCommand="SELECT * FROM [GV]"></asp:SqlDataSource>
    </div>
    </form>
</body>
</html>
GridViewSelectRow.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class GridViewSelectRow : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.GridView1, "Select$" + e.Row.RowIndex);
            e.Row.Style["cursor"] = "hand";
        }
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridViewRow row = ((GridView)sender).SelectedRow;
        this.sID.Text = row.Cells[0].Text;
        this.sUniqueID.Text = row.Cells[1].Text;
        this.sPrice.Text = row.Cells[2].Text;
        this.sAmount.Text = row.Cells[3].Text;
        this.sCreateDate.Text = row.Cells[4].Text;
    }
}