使用旁边的按钮在gridview中显示数据。 [英] Displaying data in a gridview with a button next to it.

查看:71
本文介绍了使用旁边的按钮在gridview中显示数据。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以表格的形式显示类别名称。在类别名称列旁边,我想要一个包含按钮的列。单击此按钮,它应该重定向到另一个页面,显示有关该特定类别的更多详细信息。



你能帮助我吗?



我尝试过:



 protected void Page_Load(object sender,EventArgs e )
{
SqlConnection conn = new SqlConnection(@Data Source = NASHIISHEENA; Initial Catalog = HousekeepingPortal_DB; Integrated Security = True);
SqlCommand cmd = new SqlCommand(从tblCategory中选择Cat_Name,conn);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();

GridView1.DataSource = dr;
GridView1.DataBind();
conn.Close();
}

解决方案

参考此样本



< asp:GridView runat =serverID =GridView1AutoGenerateColumns =false> 
< Columns>
< asp:BoundField HeaderText =类别名称DataField =Cat_Name/>
< asp:HyperLinkField DataTextField =Cat_NameDataNavigateUrlFields =Cat_NameDataNavigateUrlFormatString =〜/ Details.aspx?category = {0}
HeaderText =DetailsItemStyle-Width =150 />
< / Columns>
< / asp:GridView>





详情页面:

公共部分课详情: System.Web.UI.Page 
{
protected void Page_Load(object sender,EventArgs e)
{
string categroy = Request.QueryString [category];
//您填写详细信息的代码

}
}





参考网格中的Hpyer链接列


I want to display category names in the form of a table. Next to the category name column, I want to have a column containing buttons. On clicking this button, it should redirect to another page showing more details about that specific category.

Could you help me out?

What I have tried:

protected void Page_Load(object sender, EventArgs e)
{
   SqlConnection conn = new SqlConnection(@"Data Source=NASHIISHEENA;Initial Catalog=HousekeepingPortal_DB;Integrated Security=True");
   SqlCommand cmd = new SqlCommand("Select Cat_Name from tblCategory",conn);
   conn.Open();
   SqlDataReader dr = cmd.ExecuteReader();

   GridView1.DataSource = dr;
   GridView1.DataBind();
   conn.Close();
}

解决方案

refer this sample

<asp:GridView runat="server" ID="GridView1" AutoGenerateColumns="false">
          <Columns>
              <asp:BoundField HeaderText="Category Name " DataField="Cat_Name" />
              <asp:HyperLinkField DataTextField="Cat_Name" DataNavigateUrlFields="Cat_Name" DataNavigateUrlFormatString="~/Details.aspx?category={0}"
                  HeaderText="Details" ItemStyle-Width="150" />
          </Columns>
      </asp:GridView>



In details page:

public partial class Details : System.Web.UI.Page
   {
       protected void Page_Load(object sender, EventArgs e)
       {
          string categroy =  Request.QueryString["category"];
           // you code to populate the details

       }
   }



Reference Hpyer link column in gridivew


这篇关于使用旁边的按钮在gridview中显示数据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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