且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在asp,net中找到GridView控件的特定行详细信息

更新时间:2023-10-13 07:57:22

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!!!