单击行单元格时,从Gridview中搜索记录 [英] Search the Records from Gridview when click on Row Cell

查看:78
本文介绍了单击行单元格时,从Gridview中搜索记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在单击行单元格时从Gridview中搜索记录
================================================== ======

尊敬的朋友,

我正在Asp.net,C#,Sqlserver 2005上工作

我已经通过连接数据库在Gridview中显示了所有记录.

现在我需要按行搜索记录-单元格单击事件

我的gridview为Displays ...所有这些数据库显示....我只需要按行单击事件进行搜索.


| TNo | TrainId |火车名称|时机|来自|致
================================================== =======================
选择| 1154 | Nz5468 | NizamuddinExpr |上午8:00 |海德|德里
选择| 1125 | ShExp2568 | ShatvanaExpr |上午9:00 | Vijaywada |塞巴德

 选择 |  1154  | Nz5468 | NizamuddinExpr |上午8:00 |海德|新德里
选择 |  1125  | ShExp2568 | ShatvanaExpr |上午9:00 | Vijaywada |塞巴德



 选择 |  1154  | Nz5468 | NizamuddinExpr |上午8:00 |海德|新德里
选择 |  1125  | ShExp2568 | ShatvanaExpr |上午9:00 | Vijaywada |塞巴德


 选择 |  1154  | Nz5468 | NizamuddinExpr |上午8:00 |海德|新德里
选择 |  1125  | ShExp2568 | ShatvanaExpr |上午9:00 | Vijaywada |塞巴德



 选择 |  1154  | Nz5468 | NizamuddinExpr |上午8:00 |海德|新德里
选择 |  1125  | ShExp2568 | ShatvanaExpr |上午9:00 | Vijaywada |塞巴德




现在,我需要通过单击单元格TrainId(Nz5468)来搜索记录.

假设我单击TrainId- Nz5468 ...它应该在gridview中显示数据库中该特定ID的所有记录.

我点击过的火车ID是什么....它应该搜索特定的记录并在相同的gridview中显示它

请通过单击Gridview行单击事件来帮助我,如何执行此操作.作为单元格[2]

解决方案

在您的gridview中,添加一个具有commandName为select的命令按钮.

在您的gridview rowdatabound事件(对于数据行)中,添加以下脚本:

  For  x  As  整数 =  0  收件人 e.Row.Cells.Count-"   __ doPostBack('" + gridClientId.Replace(  _"  


")+ ','选择


" + e.Row.RowIndex.ToString + " ) e.Row.Cells(x).Attributes.Add(" cursor:hand;") 下一步



这将在网格行上触发选择命令.将其放置在适当的位置后,您便可以加入rowcommand事件,并以常规方式获取单元格值.

抱歉,您想要c#

  for ( int  x =  0 ; x <  = e.Row.Cells.Count- 1 ; x ++ ){
e.Row.Cells(x).Attributes.Add("   __ doPostBack('" + gridClientId.Replace(  _"  


Search the Records from Gridview when click on Row Cell
========================================================

Dear Friends,

Am working on Asp.net, C#, Sqlserver 2005

I have Displayed all the Records in Gridview by connecting with Database.

Now i need to search the records by row - cell click event

My gridview as Displays...all these displays from database....Just i need to search by row click event.


| TNo | TrainId | TrainName | Timings | From | To
===========================================================================
Select | 1154 | Nz5468 | NizamuddinExpr | 8:00 am | Hyd | Delhi
Select | 1125 | ShExp2568 | ShatvanaExpr | 9:00 am | Vijaywada | Secbad

Select  | 1154  | Nz5468     | NizamuddinExpr  | 8:00 am    |  Hyd       | Delhi
Select  | 1125  | ShExp2568  | ShatvanaExpr    | 9:00 am    | Vijaywada  | Secbad



Select  | 1154  | Nz5468     | NizamuddinExpr  | 8:00 am    |  Hyd       | Delhi
Select  | 1125  | ShExp2568  | ShatvanaExpr    | 9:00 am    | Vijaywada  | Secbad


Select  | 1154  | Nz5468     | NizamuddinExpr  | 8:00 am    |  Hyd       | Delhi
Select  | 1125  | ShExp2568  | ShatvanaExpr    | 9:00 am    | Vijaywada  | Secbad



Select  | 1154  | Nz5468     | NizamuddinExpr  | 8:00 am    |  Hyd       | Delhi
Select  | 1125  | ShExp2568  | ShatvanaExpr    | 9:00 am    | Vijaywada  | Secbad




Now i need to Search the Records by clicking on cell TrainId(Nz5468).

Suppose if i click the TrainId- Nz5468...it should display all the records of that particular id from database in gridview.

What ever the Train id i clicks....it should search the particular records and display it in that same gridview

Please help me, how to do this, by clicking Gridview Row click event. as cell[2]

Thanks.

解决方案

In your gridview, add a command button with commandName of select.

In your gridview rowdatabound event (for a data row) add the following script:

For x As Integer = 0 To e.Row.Cells.Count - 1
                e.Row.Cells(x).Attributes.Add("onclick", "__doPostBack('" + gridClientId.Replace("_", "


") + "','Select


" + e.Row.RowIndex.ToString + "')") e.Row.Cells(x).Attributes.Add("style", "cursor:hand;") Next



This will fire the select command on the grid row. Once you have this in place you can then hook into the rowcommand event and get your cell values in the normal way.

Sorry, you wanted c#

for (int x = 0; x <= e.Row.Cells.Count - 1; x++) {
	e.Row.Cells(x).Attributes.Add("onclick", "__doPostBack('" + gridClientId.Replace("_", "


这篇关于单击行单元格时,从Gridview中搜索记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆