Click here to Skip to main content
15,881,882 members
Articles / Web Development / ASP.NET

A simple method to select a row in a GridView control in ASP.NET 2.0

Rate me:
Please Sign up or sign in to vote.
1.50/5 (2 votes)
1 Aug 2007CPOL 29.5K   189   14  
A simple way to select/deselect a row in a GridView control in ASP.NET 2.0.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SelectingRow.aspx.cs" Inherits="SelectingRow" %>

<!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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table border="1" style="left: 267px; width: 376px; position: absolute; top: 260px;
            height: 1px">
            <tr>
                <td style="width: 763px; height: 21px">
                    ADMIN PAGE</td>
            </tr>
            <tr>
                <td align="center" style="width: 763px; position: relative; height: 117px" valign="top">
                    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Height="1px"
                         
                        Width="363px" OnRowDataBound="GridView1_RowDataBound">
                        <Columns>
                            <asp:TemplateField HeaderText="Edit">
                                <HeaderStyle HorizontalAlign="Left" />
                                <ItemTemplate>
                                    &nbsp;<asp:CheckBox ID="chkEdit" runat="server" AutoPostBack="True" OnCheckedChanged="chkEdit_CheckedChanged" />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="News">
                                <ItemStyle HorizontalAlign="Left" />
                                <HeaderStyle HorizontalAlign="Left" />
                                <ItemTemplate>
                                    <asp:TextBox ID="txtheading" runat="server" ReadOnly="True" TextMode="MultiLine" Enabled="False"></asp:TextBox>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <asp:Button ID="btnDelete" runat="server" Enabled="False"
                                        Text="Delete" />
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                </td>
            </tr>
            <tr>
                <td align="center" colspan="2" style="position: relative; height: 5px" valign="top">
                </td>
            </tr>
        </table>
    
    </div>
    </form>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions