如何在点击视图中显示页面中的网格视图数据 [英] How to show data of grid view in page at the click on view

查看:106
本文介绍了如何在点击视图中显示页面中的网格视图数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..

如果我们点击那个gridview的视图链接或按钮

Hi..
How we show data of grid view on page if we click on view link or button of that gridview

推荐答案

获取数据网格视图的RowCommand命令属性。当您单击视图时,在后面的代码中写下波纹管代码它转到行命令并在此检查命令名称我有命令名称编辑更新记录我将所选行值分配给文本框您也可以将这些值分配给标签。





Take RowCommand command Property of data grid view. and write bellow code in code behind when you click on view it go to row command and check for command name here i have command name Edit Record for update I assign the selected row value to textboxes you can assign that values to label also.


protected void grdvwParts_RowCommand(object sender, GridViewCommandEventArgs e)
       {
           try
           {


               int id = Convert.ToInt32(e.CommandArgument);

               if (e.CommandName.Equals("EditRecord"))                               //onclick edit link button of grigview
               {
                   GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
                   string partCode = row.Cells[1].Text;
                   string partname = row.Cells[2].Text;
                   string section = row.Cells[3].Text;
                   tbcPrtCode.Text = partCode;
                   tbxPrtNm.Text = partname;
                   ddlsection.SelectedItem.Text = section;

               }
               if (e.CommandName.Equals("DeleteRecord"))                               //onclick remove link button of grigview
               {
                   // ScriptManager.RegisterStartupScript(this, this.GetType(), "alertmessage", "javascript:alert(' Are you sure')", true);
                   con = new SqlConnection(strConnString);
                   cmd = new SqlCommand(String.Format("DELETE FROM Parts WHERE(prt_id ='" + id + "')"), con);
                   cmd.Connection = con;
                   con.Open();
                   int result = cmd.ExecuteNonQuery();
                   con.Close();


               }
           }
           catch (Exception ex)
           {
               throw ex;
           }
           finally
           {
               if (con != null)
               {
                   con.Close();
                   con.Dispose();
               }
           }





希望它能帮到你



hope it will help you


这篇关于如何在点击视图中显示页面中的网格视图数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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