C#中网格的行索引 [英] Row Index in of grid in c#

查看:114
本文介绍了C#中网格的行索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我努力获得行索引.我得到了链接.但是我想知道正在发生什么过程....

GridViewRow gvr =(GridViewRow)((LinkBut​​ton)e.CommandSource).NamingContainer;

我想对此行进行解释...

什么和铸造正在进行中.我需要什么目的?

hi All,

i worked to get row index.. i got link . But i want to know what process is going on....

GridViewRow gvr = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;

I wanna explanation for this line...

what and the casting is going on. wat purpose i need?

推荐答案



在行命令中,如果要获取当前行或其索引,则不可能直接进行.有两种方法,一种是在链接按钮上的行创建事件上(假设它用于行命令)将行索引保存在链接按钮命令的参数属性中.

并使用e.CommandArgument
从行命令事件中获取参数
但是,如果您要发送另一个值作为命令参数,则会产生问题.要解决此问题,只需使用以下代码

GridViewRow row =(GridViewRow)((((LinkBut​​ton)e.CommandSource).NamingContainer);

此处导致进入行命令事件的链接按钮(或任何源).现在您已经选择了行,因此您不需要任何索引,并且可以直接访问任何行变量,因为示例代码如下所示
标签lblProdId =(Label)row.FindControl("lblproductId");

因此,整个代码只有两行.下面我写完整的代码

GridViewRow row =(GridViewRow)((((LinkBut​​ton)e.CommandSource).NamingContainer);

标签lblProdId =(Label)row.FindControl("lblproductId");

谢谢
Vishwa
Hi,

In row command if you want to get the current row or its index, It is not directly possible. There is two way, one is on row created event on the link button(suppose, it is used for row command) save row index in link button command argument attribute.

And get the argument from row command event using e.CommandArgument

But if you want to send another value as a command argument then it creates problem. To solve this just use this code

GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);

Here link button (or any source) that cause to enter in row command event. Now you have selected row so you don’t need any index and directly access any row variable as sample code is given below
Label lblProdId = (Label)row.FindControl("lblproductId");

So whole code is just two line. Below I write whole code

GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);

Label lblProdId = (Label)row.FindControl("lblproductId");

Thanks
Vishwa


这篇关于C#中网格的行索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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