如何在asp,net中找到GridView控件的特定行详细信息 [英] How to find Particular Row Details of GridView Control in asp,net

查看:57
本文介绍了如何在asp,net中找到GridView控件的特定行详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网格视图控件,每当页面加载所有可用的数据都会显示在我的GridView上,我在每一行上放置一个链接按钮,现在我的问题是每当我点击支付按钮页面将仅通过获取特定行的详细信息重定向到另一个页面。以下是我的代码....

I have a Grid View Control, whenever the page loads all the available Data will display on my GridView and i place a Link Button on each row, now my problem is Whenever i Click on pay button the page will Redirect to another page by taking the details of that particular Row only. Below is my code....

<asp:GridView ID="gvap" runat="server" AutoGenerateColumns="false" >
  <Columns>
  <asp:BoundField HeaderText="Course" DataField="course_name" />
  <asp:BoundField HeaderText="Start Date" DataField="start_date" />
  <asp:BoundField HeaderText="End Date" DataField="end_date" />
  <asp:BoundField HeaderText="Timings" DataField="timings" />
  <asp:BoundField HeaderText="Amount" DataField="amount" />
  <asp:TemplateField>
  <ItemTemplate>
  <asp:LinkButton runat="server" ID="lbtn" Text="Pay" PostBackUrl="~/EBS.aspx"></asp:LinkButton>
  </ItemTemplate>
  </asp:TemplateField>
  </Columns>
  </asp:GridView>




protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection();
        conn.ConnectionString = "Data Source=(local); Initial Catalog=123; User Id=sa; Password=123; Integrated Security=false";


        //Assigning Query
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = conn;
        cmd.CommandText = "select course_name , start_date , end_date, timings, amount from courses where start_date>=GETDATE()";
        cmd.CommandType = CommandType.Text;
        

        //Execute the COmmand
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.SelectCommand = cmd;
        DataSet ds = new DataSet();
        da.Fill(ds);
        gvap.DataSource = ds;
        gvap.DataBind();    
    }

推荐答案

shabarinadh.vempati试图说的是 -



将OnRowCommand事件添加到您的gridview,例如 -

What shabarinadh.vempati is trying to say is -

Add 'OnRowCommand' event to your gridview like-
<asp:gridview id="gvap" runat="server" autogeneratecolumns="false" onrowcommand="gvap_RowCommand" xmlns:asp="#unknown"></asp:gridview>





并将linkname属性添加到您的linkbutton



然后在代码隐藏文件的事件处理程序上执行某些操作喜欢 -



and add commandname property to your linkbutton

and then on its eventhandler in code behind file do something like -

protected void gvap_RowCommand(objectsender,GridViewCommandEventArgs e)
    {
        if (e.CommandName == "EditMe")
        {
            GridViewRow grow = (GridViewRow)(((linkbutton)e.CommandSource).NamingContainer);
            hdn.Value = grow.Cells[1].Text;


        }



做这样的事情尝试使用任何状态管理技术访问网格的行值..



还有一件事是在函数中编写整个sql interation和数据绑定,并在页面加载时使用(!ispostback)调用它,例如 -




do something like this try to access the grid's row values using any state management technique..

One more thing write the whole sql interation and databinding in a function and call it on page load with a (!ispostback)like -

public void populategrid()
{
SqlConnection conn = new SqlConnection();
        conn.ConnectionString = "Data Source=(local); Initial Catalog=123; User Id=sa; Password=123; Integrated Security=false";
 

        //Assigning Query
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = conn;
        cmd.CommandText = "select course_name , start_date , end_date, timings, amount from courses where start_date>=GETDATE()";
        cmd.CommandType = CommandType.Text;
        
 
        //Execute the COmmand
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.SelectCommand = cmd;
        DataSet ds = new DataSet();
        da.Fill(ds);
        gvap.DataSource = ds;
        gvap.DataBind(); 
}





然后在页面加载



and then on page load

if(!ispostback)
{
populategrid();
}





希望这会有所帮助!



hope this helps!


我在 LinkBut​​ton

I added a code in LinkButton
<asp:linkbutton runat="server" id="lbtn" text="Pay" commandargument="<%# Eval("amount") %>" commandname="Select" xmlns:asp="#unknown"></asp:linkbutton>

  <asp:label id="lblMessage" runat="server" xmlns:asp="#unknown"></asp:label>   
    
  <asp:textbox id="txtMobile" runat="server" xmlns:asp="#unknown"></asp:textbox>





添加了我我的代码在后面





Added In my code Behind

protected void gv_rowcommand(object sender, GridViewCommandEventArgs e)
   {
       if (e.CommandName == "Select")
       {
           txtMobile.Text = Convert.ToString(e.CommandArgument);
           lblMessage.Text = "Amount = ";

       }
   }







It将显示所选行数量.....



现在我想显示像这样的整行信息......




It will display the Selected Row Amount.....

Now i want to Display Entire Row Information like that......

我在这个页面加载时的第一次数据显示的一种方式



onRowdatabound网格事件你可以添加属性回发通过在查询字符串中附加所有列值来链接按钮

现在当您点击链接时,它会将您重定向到该页面,您可以从该字符串中获取所有值。



希望这有帮助!!!
One way i have for this
at the time page load when first time data diplayed
onRowdatabound event of grid you can add attribute postback url to link button
by appending all column values in query string now when you will click on link it redirect you to that page on that you can fetch all values from this string.

Hope this helps!!!


这篇关于如何在asp,net中找到GridView控件的特定行详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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