它是奇怪的如果我使用链接按钮的查找控件,我得到空Gridview。 [英] It Is Strange If I Use Find Control For Linkbutton, I Am Getting Empty Gridview.

查看:82
本文介绍了它是奇怪的如果我使用链接按钮的查找控件,我得到空Gridview。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我使用Gridview和数据库绑定。并且,我使用OnRowDataBound =Gridprepack_RowBound。

  protected   void  Gridprepack_RowBound( object  sender,GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblqty =(Label)e.Row.FindControl( lblqty1);
Label lblpriceprepack =(Label)e.Row.FindControl( lblpriceprepack);
Label lblpackprice =(Label)e.Row.FindControl( lblpackprice);
标签lblmapprice =(标签)e.Row.FindControl( lblmapprice);
标签lbladdtocart =(标签)e.Row.FindControl( lbladdtocart);
LinkBut​​ton lnkviewcart12 =(LinkBut​​ton)e.Row.FindControl( likbtn);




}





因为我使用LinkBut​​ton查找控件,我的整个gridview显示为空白。但没有错误!不过没有例外..



一旦我删除了这一行LinkBut​​ton lnkviewcart12 =(LinkBut​​ton)e.Row.FindControl(likbtn); 。整个gridview显示完美。



为什么会发生这种情况?



谢谢!..

解决方案

On Row数据绑定... Word自己有意义......



之后databind();

每个控件或我们想要在特定行上发生的事情都可以通过行上绑定控制...



Linkbutton只是一个按钮我们没有绑定任何东西..



你可以观察,如果你可以使用超过链接按钮网格..

我们没有说通过查找控件中使用的ID来点击什么linkbutton ..


$ b所有链接按钮$ b我们只使用..

只说(linkbutton)发件人,Imagebutton(发件人)....





所以.....



LinkBut​​ton lnkviewcart12 =(LinkBut​​ton)e.Row.FindControl(likbtn);

不需要行数据绑定...

Hello,

I use Gridview and binding from database. And, i use OnRowDataBound="Gridprepack_RowBound" .

protected void Gridprepack_RowBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblqty = (Label)e.Row.FindControl("lblqty1");
Label lblpriceprepack = (Label)e.Row.FindControl("lblpriceprepack");
Label lblpackprice = (Label)e.Row.FindControl("lblpackprice");
Label lblmapprice = (Label)e.Row.FindControl("lblmapprice");
Label lbladdtocart = (Label)e.Row.FindControl("lbladdtocart");
LinkButton lnkviewcart12 = (LinkButton)e.Row.FindControl("likbtn");
.
.
.
.
}



as i used LinkButton find control, my whole gridview shows just blank. But no Error ! No exception though..

once i removed this line "LinkButton lnkviewcart12 = (LinkButton)e.Row.FindControl("likbtn");" . Whole gridview shows perfectly.

why it is happening like that?

Thank you!..

解决方案

On Row Data bound... The Word it self has the meaning...

After the databind();
What will happening in each is control or what we want on the particular row can be control by the on row bound...

Linkbutton is just a button we doesn't bind anything on it..

You can observe, If u may use more than link button on the grid..
we doesn't say what linkbutton is to be click by means of "ID" which is used in find control..

for all linkbutton we only use..
just say (linkbutton )sender,Imagebutton(sender)....


So.....

LinkButton lnkviewcart12 = (LinkButton)e.Row.FindControl("likbtn");
is no need on row databound...


这篇关于它是奇怪的如果我使用链接按钮的查找控件,我得到空Gridview。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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