GridView没有初始化事件 [英] Gridview not initiaing an event
本文介绍了GridView没有初始化事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个ASP.NET App,我在其中基于用户的搜索条件创建Gridview.该文件是文本制表符分隔的文件.我可以创建网格,但不能选择一行.这是我的代码和ASPX页面.
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=0;
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];
dt.Rows.Add(dr);
}
}
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<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:GridView>
<p>
<asp:Label ID="Label1" runat="server" Text="Search by item"
style="z-index: 1; left: 10px; top: 39px; position: absolute"></asp:Label>
</p>
<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>
</form>
</body>
</html>
请向我提供一种供用户选择行并从该选择中生成事件的方法.
谢谢.
Please provide me with a way for the user to select a row and generate an event from that selection.
Thank you.
推荐答案
请检查此链接
http://msmvps. com/blogs/deborahk/archive/2010/01/25/asp-net-selecting-a-row-in-a-gridview.aspx [ http://highoncoding.com/Articles/188_GridView_Clickable_Row.aspx [ http://www.dreamincode.net/forums/topic/155444-gridview-rowclick-event / [^ ]
希望对您有所帮助:)
Hi,
Please check this links
http://msmvps.com/blogs/deborahk/archive/2010/01/25/asp-net-selecting-a-row-in-a-gridview.aspx[^]
http://highoncoding.com/Articles/188_GridView_Clickable_Row.aspx[^]
http://www.dreamincode.net/forums/topic/155444-gridview-rowclick-event/[^]
I hope it will help :)
这篇关于GridView没有初始化事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文