在gridview中的rowdatabound上分配列值 [英] assign columns value on rowdatabound in gridview

查看:79
本文介绍了在gridview中的rowdatabound上分配列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网格视图中面临一个问题,基本上我想要实现的是以下内容:我有一个网格视图,其中我的第一列是链接按钮,我必须设置一个条件,使第二列的值是并被输入到ac#方法中,用于填充我需要在第一列中分配的值.

我正在尝试下面的代码,但是当我查看网格时,其显示的第一列值为空白.
Aspx页面:

I am facing a problem in grid view, basically what i am trying to achieve is below: I have a grid view in which my first column is a link button, i have to put a condition where value from my 2nd column is taken and is input to a c# method for poulating a value which i need to assign into my first column.

I am trying below code however when i view my grid its showing 1st columns value as blank.
Aspx page:

<asp:TemplateField HeaderText="FileName" ItemStyle-HorizontalAlign="Center">  <itemtemplate> <asp:LinkButton ID="btn"  runat="server" CommandName="Click"/> </itemtemplate>

aspx.cs-我在rowdatabound上编写的以下代码

aspx.cs - below code i have written on rowdatabound

if (e.Row.RowType == DataControlRowType.DataRow) 
{
 int EmpiD = Int32.Parse(e.Row.Cells[2].Text);
 DataSet EmpIDDs = GetEMP.getValue(EmpiD);
 DataRow EmpRow = EmpIDDs.Tables[0].Rows[0];
 e.Row.Cells[0].Text = EmpRow[3].ToString(); }

如果有任何解决方案,请帮助我

Please help me if you have any solution

推荐答案

在行数据绑定内,通过以下代码获取列对象

Inside row databound, get the column object by the following code

Label TestLabel = (Label)e.Row.FindControl("MyLabel");
   TestLabel.Text= "Hello";



然后为其分配任何属性值.



Then assign any property value to it.


写入gridview行命令事件args

此处的命令名称为

声明字符串value = string.empty;

if(e.commnadName =="click")
{

//如果您放置文本框,请找到文本框
Gridviewrow row = gridview1.rows [2] as gridviewrow

文本框txtid = row.fincontrol(项目模板中的txtid");

值= txtid.Text; //在这里您可以在文本框中读取值;

}


告诉我,不管您是否了解
Write in gridview row command event args

here the command name is click

declare string value=string.empty;

if(e.commnadName=="click")
{

//if you put the text box find the text box
Gridviewrow row= gridview1.rows[2] as gridviewrow

textbox txtid=row.fincontrol("txtid in item template");

value=txtid.Text; // Here you can read the value in the textbox ;

}


inform me, you get it or not


为此,您需要找到列单元格的控件,然后需要更改值.

希望对您有帮助.
Hi For this you need to find the control of the column''s cell and then you need to change the value.

Hope this will help you.


这篇关于在gridview中的rowdatabound上分配列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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