本文介绍了将“查看”和“删除”按钮添加到gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一个gridview,其中我通过sql命令绑定数据。 aspx页面: < asp:GridView ID =gv_adsrunat =server> < / asp:GridView> aspx.cs: protected void Page_Load( object sender,EventArgs e) { if (!IsPostBack) { BindGridview(); } } 受保护 void BindGridview() { var o =会话[ 通告]; if (o!= null ) { ses = o.ToString(); } SqlCommand cmd = new SqlCommand( sps_myads,con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue( @ email,ses); 尝试 { con.Open(); gv_ads.EmptyDataText = 找不到记录; gv_ads.DataSource = cmd.ExecuteReader(); gv_ads.DataBind(); con.Close(); } catch (例外情况) { throw ex; } } 存储过程: ALTER PROCEDURE [dbo]。[sps_myads] @ email nvarchar ( 100 ) AS BEGIN 选择 CONVERT ( VARCHAR ( 10 ),registertime, 104 ) as Register_On,r.ad_id,c.category_name,sc.subcategory_name,title from dbo.tbl_adregister r INNER JOIN tbl_category c ON r.category = c.category_id INNER JOIN tbl_subcategory sc on r.subcategory = sc.subcategory_id 其中 useremail = @ email END 根据我的查询显示结果,我的问题是我的结果右侧每行需要两个按钮:一个是View,另一个是Delete。 查看按钮:当我点击查看时按钮它将重定向到其他页面,其中ad_id作为参数,以便我可以显示一个特定点击行ad_id的完整详细信息。 删除按钮:当我点击特定行的删除按钮时应该要求确认对话框删除,点击确定后会删除gridview中的特定行数据。 请帮助程序员。解决方案 I have one gridview in which i bind data through sql command.aspx page:<asp:GridView ID="gv_ads" runat="server" ></asp:GridView>aspx.cs:protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindGridview(); } }protected void BindGridview() { var o = Session["advertise"]; if (o != null) { ses = o.ToString(); } SqlCommand cmd = new SqlCommand("sps_myads", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@email", ses); try { con.Open(); gv_ads.EmptyDataText = "No Records Found"; gv_ads.DataSource = cmd.ExecuteReader(); gv_ads.DataBind(); con.Close(); } catch (Exception ex) { throw ex; } }stored procedure:ALTER PROCEDURE [dbo].[sps_myads]@email nvarchar(100)ASBEGINselect CONVERT(VARCHAR(10),registertime ,104) as Register_On, r.ad_id, c.category_name, sc.subcategory_name, title from dbo.tbl_adregister r INNER JOIN tbl_category c ON r.category = c.category_id INNER JOIN tbl_subcategory sc on r.subcategory = sc.subcategory_idwhere useremail=@emailENDIt showing me result according to my query, my problem is i need two buttons for every row at right side of my result: one is View and other is Delete.View button: when i click on view button it will redirect to other page with "ad_id" as parameter so that i can display complete details of one particular clicked row "ad_id".Delete button: when i click on delete button of particular row it should ask a confirmation dialog to delete and after click ok it will delete particular row data from gridview.Please help programmers. 解决方案 这篇关于将“查看”和“删除”按钮添加到gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-23 03:49