VC# 2008 ASP.NET Gridview1获取任意行列的值

来源:互联网 发布:淘宝网火车票 编辑:程序博客网 时间:2024/04/27 03:09
 Gridview1在使用模版情况下,获取任意行列值


protected void gvMasterResult_RowCommand(object sender, GridViewCommandEventArgs e)
 {
 int aa  = Convert.ToInt32(e.CommandArgument); //待处理的行下标 
 
 String str = (Gridview1.Rows[aa].FindControl("LinkButton1")).Text.ToString().Trim();
 }

 

Gridview1在不使用模版情况下,获取任意行列值
前台:
<asp:TemplateField HeaderText="编码">
<ItemTemplate>
<b>
    <asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Bind("item_id")%>'>LinkButton</asp:LinkButton>
</b>
</ItemTemplate>
</asp:TemplateField>

后台:

在Gridview1的RowCommand事件下使用
protected void gvMasterResult_RowCommand(object sender, GridViewCommandEventArgs e)
 {
 int aa  = Convert.ToInt32(e.CommandArgument); //待处理的行下标  需要另行处理(RowCreated事件处理) 不然会报错    
 string No_txt1 = (gvMasterResult.Rows[aa].Cells[1]).Text;
 String str = ((LinkButton)gvMasterResult.Rows[aa].FindControl("LinkButton1")).Text.ToString().Trim();
 }


在Gridview1事件中重新生成LinkButton1
protected void gvMasterResult_RowCreated(object sender, GridViewRowEventArgs e)
 {
 if (e.Row.RowType == DataControlRowType.DataRow)
 {
 LinkButton LinkButton1 = (LinkButton)e.Row.FindControl("LinkButton1");
 LinkButton1.CommandArgument = e.Row.RowIndex.ToString();
 }
 }

 

原创粉丝点击