从GridView获取值 [英] Get values from gridview

查看:82
本文介绍了从GridView获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在下面有此事件,试图从gridview读取值. gridview不为空时无法获取任何数据.



Hi

I have this event below, trying to read values from a gridview. Am not geting any data while gridview is not empty.



 protected void btnSendTravelingClaims_Click(object sender, EventArgs e)
        {
      Label lblReason =(Label)grvTravelClaims.FindControl("lblReason");
      Label lblDate = (Label)grvTravelClaims.FindControl("lblDate");
      Label lblLocation = (Label)grvTravelClaims.FindControl("lblLocation");
      Label lblKillometers = (Label)grvTravelClaims.FindControl("lblKillometers");

string _reason=lblReason.Text;
       }



当我踩刹车时,"_ reason"为空.

我要做的主要事情是使用流编写器将gridview中的所有内容写入文件.



When I put a brakepoint the "_reason" is empty.

The main thing i want to do is to write every thing in the gridview to a file using stream writer.

推荐答案

使用RowCommand网格视图事件.
在您的按钮代码中传递CommandName ="Add".
和onRowCommand
Use RowCommand event of grid view.
pass CommandName="Add" in your button code.
and onRowCommand
if(e.CommandName=="Add")
    {
      // Convert the row index stored in the CommandArgument
      // property to an Integer.
      int index = Convert.ToInt32(e.CommandArgument);

      // Retrieve the row that contains the button clicked 
      // by the user from the Rows collection.
      GridViewRow row = ContactsGridView.Rows[index];
//now you can retrive any cell data of taht row
string demo=row.Cells[4].Text;


^ ]


http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcommand.aspx[^]


这篇关于从GridView获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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