I put a gridview on a page and populate it. But nothing in the gridview is
selectable.

 

How can I make items in the gridview selectable?

 

Here is the code.

 

 

Thanks to all.

 

Greg

 

HTML:

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

    <div>

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

            CellPadding="4" ForeColor="#333333" GridLines="None"
Height="240px" 

            Width="248px">

            <RowStyle BackColor="#EFF3FB" />

            <FooterStyle BackColor="#507CD1" Font-Bold="True"
ForeColor="White" />

            <PagerStyle BackColor="#2461BF" ForeColor="White"
HorizontalAlign="Center" />

            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True"
ForeColor="#333333" />

            <HeaderStyle BackColor="#507CD1" Font-Bold="True"
ForeColor="White" />

            <EditRowStyle BackColor="#2461BF" />

            <AlternatingRowStyle BackColor="White" />

        </asp:GridView>

        <br />

        <br />

        <asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Button" />

    </div>

    </form>

 

 

CODE:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;

 

public partial class _Default : System.Web.UI.Page 

{

    DataTable DT;

   

    protected void Page_Load(object sender, EventArgs e)

    {

        if (!IsPostBack)

        {

            DT = new DataTable();

            DT.Columns.Add(new DataColumn("Data1",
Type.GetType("System.String")));

            DT.Columns.Add(new DataColumn("Data2",
Type.GetType("System.String")));

            DT.Columns.Add(new DataColumn("Data3",
Type.GetType("System.String")));

            DT.Columns.Add(new DataColumn("Data4",
Type.GetType("System.String")));

            DT.Columns.Add(new DataColumn("Data5",
Type.GetType("System.String")));

            Session["Cart"] = DT;

            

            

        }

       

        

 

    }

 

    private void FillCart()

    {

        DT = (DataTable)Session["Cart"];

        DataRow DR = DT.NewRow();

        DR["Data1"] = "test1";

        DR["Data2"] = "test2";

        DR["Data3"] = "test3";

        DR["Data4"] = "test4";

        DR["Data5"] = "test5";

        DT.Rows.Add(DR);

        

        Session["Cart"] = DT;

        GridView1.DataSource = DT;

        GridView1.DataBind();

    }

 

    protected void Button1_Click(object sender, EventArgs e)

    {

        FillCart();

    }

}

 

Reply via email to