如何在不使用任何按钮或链接按钮的情况下从网格视图中选择一行 [英] How to select a row from grid view without using any button or linkbutton

查看:76
本文介绍了如何在不使用任何按钮或链接按钮的情况下从网格视图中选择一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过单击(鼠标)选择一行,这些数据将显示在某些文本框中. :((请帮助.
请详细说明..

How to select a row by clicking(mouse) a row and thae data will show in some textbox. :(( plz help.
plz give details..

推荐答案

假设datagridview的名称为dgvGrid,文本框的名称为txtName,现在为:-

在datagridview的click事件上添加以下代码:-


Supposing the name of the datagridview is dgvGrid and Textbox name is txtName now:-

on click event of datagridview add the following code:-


if (dgvGrid.Rows.Count > 0 &  dgvGrid.CurrentRow.Index>=0)
           {
              
               if (dgvGrid.Rows[dgvGrid.CurrentRow.Index].Cells[dgvGrid.CurrentCell.ColumnIndex].Value != null)
               {
                   txtName.Text = dgvGrid.Rows[dgvGrid.CurrentRow.Index].Cells[dgvGrid.CurrentCell.ColumnIndex].Value.ToString();
               }
           }


GridView呈现为浏览器的表.
您可以使用Select CommandField选择该行.
处理GridView1_RowCommand事件以访问选定的值.

希望对您有帮助.
GridView is rendered as a table to the browser.
You can use Select CommandField to select the row.
Handle the GridView1_RowCommand event to access the selected values.

Hope it helps.


如果有帮助,请告知我,或者告诉我您究竟在寻找什么.
Please inform me if it helps you or let me know what are you exactly looking for.


这篇关于如何在不使用任何按钮或链接按钮的情况下从网格视图中选择一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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