I'm building a asp.net page in C#. I have a GridView that when I click on it I want the content in the cell. The problem is that nothing at all happens when I click on in. What is wrong?
In my aspx-file:
<asp:GridView ID="GridView1" runat="server" Height="224px" Width="589px" IsItemClickEnabled="True" SelectionChanged="GridView1_SelectedIndexChanged" OnSelectedIndexChanged="GridView1_SelectedIndexChanged"></asp:GridView>
In my cs-file:
protected void Page_Load(object sender, EventArgs e)
{
NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;Port=5432;Database=ssys;User Id=postgres;Password=postgres;"); //Skapar connectionobjektet
conn.Open();
NpgsqlCommand command = new NpgsqlCommand("SELECT * FROM times", conn);
NpgsqlDataReader dr = command.ExecuteReader();
GridView1.DataSource = dr;
GridView1.DataBind();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
string item = (string)(GridView1.Rows[0].Cells[0]).Text;
MessageBox.Show(item);
}