我如何使用Asp.Net获得网格控制中的特定行值 [英] How I Get Particular Row Value In Grid Control Using Asp.Net

查看:68
本文介绍了我如何使用Asp.Net获得网格控制中的特定行值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请为此问题提供解决方案。

please give solution for this question.

推荐答案

请参阅:

http://www.aspsnippets.com/Articles/How-to-get-Selected-来自GridView-in-ASPNet.aspx的行单元格值[ ^ ]



See this :
http://www.aspsnippets.com/Articles/How-to-get-Selected-Row-cell-value-from-GridView-in-ASPNet.aspx[^]

<asp:GridView ID="GridView1" runat="server" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"

    AutoGenerateColumns="false" OnSelectedIndexChanged = "OnSelectedIndexChanged">
    <Columns>
        <asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="150" />
        <asp:TemplateField HeaderText="Country" ItemStyle-Width="150">
            <ItemTemplate>
                <asp:Label ID="lblCountry" runat="server" Text='<%# Eval("Country") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:ButtonField Text="Select" CommandName="Select" ItemStyle-Width="150" />
    </Columns>
</asp:GridView>
<br />
<u>Selected Row Values: </u>
    <br />
<br />
<asp:Label ID="lblValues" runat="server" Text=""></asp:Label>







protected void OnSelectedIndexChanged(object sender, EventArgs e)
{
    //Accessing BoundField Column
    string name = GridView1.SelectedRow.Cells[0].Text;

    //Accessing TemplateField Column controls
    string country = (GridView1.SelectedRow.FindControl("lblCountry") as Label).Text;

    lblValues.Text = "<b>Name:</b> " + name + " <b>Country:</b> " + country;
}



-KR


-KR


private void FidnAtRow(int p)
    {
        if (GridView1.Rows.Count>p && p >= 0)
        {
            GridViewRow gr = (GridViewRow)GridView1.Rows[p];
            if (gr!=null)
            {
/// For bound feild
                Response.Write(gr.Cells[0].Text);// [0] is the cell/Column no
// in the case of template feild first find the control by using this line
Label lbl1 = (Label)gr.FindControl("Label1");
                Response.Write(lbl1.Text); 
            }
        }
    }





//////////// ////如果您在模板中有一些按钮或图像按钮或链接按钮,并且您想通过单击找到同一行中的某些内容然后使用这种方式

//拳头找到它的行,然后通过gridview行你可以找到任何东西





//////////////// In the case if you have some button or image button or link button inside template feild and you want to findout something in the same row by clicking then use this way
// fist findout its row and then by gridview row you can find anything

protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
 GridViewRow gr = (GridViewRow)(sender as Control).Parent.Parent;
/// For bound feild
                Response.Write(gr.Cells[0].Text);
// in the case of template feild first find the control by using this line
Label lbl1 = (Label)gr.FindControl("Label1");
                Response.Write(lbl1.Text); 
}


这篇关于我如何使用Asp.Net获得网格控制中的特定行值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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