行上的gridview选择以新形式打开行值 [英] gridview selection on row to open the row values in new form

查看:75
本文介绍了行上的gridview选择以新形式打开行值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在gridview中,我想在用户点击特定行时以新格式打开另一个表单我想通过将一个页面的主键传递给新页面来显示用户在特定行上选择的记录...任何人都可以告诉我如何做到这一点..是否有任何gridview事件来完成这一点点击行..我不喜欢使用项目模板和链接按钮..任何帮助???

In gridview, I want to open another form when user clicks on particular row and in new form I want to show the record as selected on particular row by user by passing primary key for one page to new page... Can anyone tell me on how to do this.. Is there any gridview event to accomplish this on click of row.. i donot prefer using item template and link button in it.. Any help???

推荐答案

HI

按照以下步骤操作:



HI
Follow these steps.

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="100%"

       OnRowDataBound="GridView1_RowDataBound">
       <Columns>
           <asp:BoundField HeaderText="SomeColumn" DataField="SomeColumn" />

       </Columns>
   </asp:GridView>





1)如上所述在网格视图中创建一个 OnRowDataBound 事件。



2)在服务器事件中将 onclick 事件添加到行中,如下所示





1) create a OnRowDataBound event to the grid view as above.

2) in the server event add onclick event to the rows as follows

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
       {
           if (e.Row.RowType == DataControlRowType.DataRow)
           {
               string primaryKey = DataBinder.Eval(e.Row.DataItem, "PrimaryKeyID") + "";
               e.Row.Attributes.Add("onclick", "opennewwindow('" + primaryKey + "')");

           }

       }





3)添加 javascript 打开一个新窗口,传递主键ID 作为参数。





3) add javascript to open a new window , by passing the primary key ID as parameter.

<script type="text/javascript">
        var opennewwindow = function (primarykey) {
            alert(primarykey);
            window.location = "Job.aspx?primarykey=" + primarykey;
        }
    </script>







样本输入运行上述:






sample input to run the above:

protected void Page_Load(object sender, EventArgs e)
       {
           if (!Page.IsPostBack)
           {
               DataTable dt = new DataTable();
               dt.Columns.Add("PrimaryKeyID", typeof(int));
               dt.Columns.Add("SomeColumn", typeof(string));
               dt.Rows.Add(1,"aaaaaaaa");
               dt.Rows.Add(2,"bbbbbbbbb");


               GridView1.DataSource = dt;
               GridView1.DataBind();
           }
       }





读取下一页中的查询字符串值





read the query string values in next page as

public partial class Job : System.Web.UI.Page
   {
       protected void Page_Load(object sender, EventArgs e)
       {
           if (!Page.IsPostBack)
           {

            int primarykey = Convert.ToInt32(Request.QueryString["primarykey"]);      
               // your code....
           }
       }


您好
您应该将primarykey列指定为DataKeynames并为该gridview创建selectedindexchanged事件。

然后在该事件中youu可以写

Hi You should assign primarykey column as DataKeynames and create selectedindexchanged event for that gridview.
Then in that event youu can write
int id = GridView1.SelectedDataKey.Value;



使用这个你将得到的id选择行然后使用查询字符串,您将使用response.redirect将该ID发布到新页面o / w将该值存储在会话变量中。



下一页你可以使用该id并根据来自数据库的id获取数据并显示在页面上。


by using this you will get id of that selected row and then using querystring you will post that id to new page using response.redirect o/w storing that id value in session variable.

And next page you can use that id and fetch data according to that id from Database and display on page.


BK 4代码。谢谢你的解决方案。我按你的方式做了,但是当我点击gridview中的特定行时,selectindexchanged没有被触发..我错过了什么?是否有一些其他功能,如autopostback = true,我错过了...... ???
BK 4 code. thanks for your solution. I did it in your way but selectedindexchanged is not fired when i click on the particular row in gridview.. did i missed something??? is there some other features like autopostback = true that i missed out...???


这篇关于行上的gridview选择以新形式打开行值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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