Click here to Skip to main content
12,550,570 members (43,342 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET
I have an ASP.NET App where I am creating a Gridview based on the user's search criteria. The file is a text tab delimited file. I am able to create the Grid but I am not able to select a row. Here is my code and ASPX page.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data;
using System.Diagnostics;
using System.Drawing;
public partial class Default3 : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        Label4.Text = "Enter Search String";
        Label4.Visible = true;
        TextBox1.Visible = true;
    protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
    protected void ImageButton3_Click(object sender, ImageClickEventArgs e)
    protected void TextBox1_TextChanged(object sender, EventArgs e)
        char t = '\u0009';
        string[] lines = System.IO.File.ReadAllLines(@"C:\ri.txt");
        DataTable dt = new DataTable();
        dt.Columns.Add("Item", typeof(System.String));
        dt.Columns.Add("Title", typeof(System.String));
        dt.Columns.Add("LastName", typeof(System.String));
        dt.Columns.Add("FirstName", typeof(System.String));
        DataRow dr = null;
        int found;
        foreach (string line in lines)
            string[] words = line.Split(new Char[] { t });
            found = words[2].IndexOf(TextBox1.Text);
            if (found > 0 )
                dr = dt.NewRow();
                dr[0] = words[0];
                dr[1] = words[2];
                dr[2] = words[3];
                dr[3] = words[4];
        GridView1.DataSource = dt;

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
    <asp:ImageButton ID="ImageButton1" runat="server" onclick="ImageButton1_Click"
        style="z-index: 1; left: 115px; top: 34px; position: absolute" />
    <asp:Label ID="Label2" runat="server"
        style="z-index: 1; left: 213px; top: 34px; position: absolute; width: 184px; height: 28px;"
        Text="Search by tittle"></asp:Label>
    <asp:ImageButton ID="ImageButton2" runat="server" onclick="ImageButton2_Click"
        style="z-index: 1; left: 445px; top: 34px; position: absolute" />
    <asp:Label ID="Label3" runat="server"
        style="z-index: 1; left: 586px; top: 34px; position: absolute"
        Text="Search By Subject"></asp:Label>
    <asp:ImageButton ID="ImageButton3" runat="server" onclick="ImageButton3_Click"
        style="z-index: 1; left: 723px; top: 34px; position: absolute" />
  <asp:GridView ID="GridView1" runat="server"
        style="z-index: 1; left: 31px; top: 158px; position: absolute; height: 256px; width: 685px">

    <asp:Label ID="Label1" runat="server" Text="Search by item"
            style="z-index: 1; left: 10px; top: 39px; position: absolute"></asp:Label>
    <asp:TextBox ID="TextBox1" runat="server" ontextchanged="TextBox1_TextChanged"
        style="z-index: 1; left: 122px; top: 67px; position: absolute" Visible="False"></asp:TextBox>
    <asp:Label ID="Label4" runat="server"
        style="z-index: 1; left: 10px; top: 79px; position: absolute"
        Text="Enter Search" Visible="False"></asp:Label>

Please provide me with a way for the user to select a row and generate an event from that selection.

Thank you.
Posted 21-Nov-12 7:42am

1 solution

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.161021.1 | Last Updated 21 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100