如何在asp.net中单击数据网格视图的数据行时重定向到新的asp页面 [英] How to Redirect to new asp page while clicking on the data row of the data grid view in asp.net

查看:80
本文介绍了如何在asp.net中单击数据网格视图的数据行时重定向到新的asp页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,





我在asp.net中的数据网格视图仅显示来自sql server数据库的选定ID作为单行。

现在我需要在单击特定ID(数据行)时显示特定页面,并且我还要显示属于所选ID的新页面中的所有详细信息(点击id)。谢谢。请帮帮我。





问候,

Rajeev K.

Dear All,


My data grid view in asp.net displays only selected id from sql server database as a single row.
Now I need to display a particular page when I click on the particular id (data row) and also I want to display all the details in a new page belongs to the selected id( on click on the id).Thanks in advance. Please help me someone.


Regards,
Rajeev K.

推荐答案

Hi 
we can call javascript function on click of datarow using below code



        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

                e.Row.Attributes.Add("onclick","javascript:test()");            
            }
        }


here we have test() javascript function using that function you can solve your problem
may it helps


您可以通过将HyperLinkField与DataNavigateUrlField组合在网格中直接进行:



You can do it directly in the grid itself by combining a HyperLinkField with a DataNavigateUrlField:

<asp:GridView ID="myGridView" runat="server">

    <Columns>

        <asp:HyperLinkField HeaderText="My ID Column" DataTextField="MY_ID_FIELD" DataNavigateUrlFields="MY_ID_FIELD" DataNavigateUrlFormatString="~/myRedirectPage.aspx?ID={0}" />

    </Columns>

</asp:GridView>


嗨tadit,



请检查我试过的代码。



protected void btnserch_Click(object sender,EventArgs e)

{







SqlConnection objsqlconnection = new SqlConnection(CONNECTIONSTRING);

string query =从注册中选择id;



SqlCommand objsqlcommand = new SqlCommand(query,objsqlconnection);

objsqlconnection.Open();



SqlDataAdapter da = new SqlDataAdapter();

DataSet ds = new DataSet();





objsqlcommand.CommandText = query;



objsqlcommand.Connection = objsqlconnection;



da = new SqlDataAdapter(objsqlcommand);



da.Fill(ds);



objsqlcommand.ExecuteNonQuery();



GridView1.DataSource = ds;

GridView1 .DataBind();

objsqlconnection.Close();



}

此代码通过从注册表中仅选择id列来返回网格。现在,当我单击id列的数据行时,我需要另一个页面,该页面应显示属于该id的所有详细信息。



问候,

Rajeev K。
Hi tadit,

Please check the code which i have tried.

protected void btnserch_Click(object sender, EventArgs e)
{



SqlConnection objsqlconnection = new SqlConnection(CONNECTIONSTRING);
string query = "Select id from registration";

SqlCommand objsqlcommand = new SqlCommand(query, objsqlconnection);
objsqlconnection.Open();

SqlDataAdapter da=new SqlDataAdapter();
DataSet ds=new DataSet();


objsqlcommand.CommandText = query;

objsqlcommand.Connection = objsqlconnection;

da = new SqlDataAdapter(objsqlcommand);

da.Fill(ds);

objsqlcommand.ExecuteNonQuery();

GridView1.DataSource = ds;
GridView1 .DataBind();
objsqlconnection.Close();

}
This code returns a grid by selecting only id column from registration table.Now when i click on the data row of the id column,i need an another page which should displays all the details belongs to that id.

Regards,
Rajeev K.


这篇关于如何在asp.net中单击数据网格视图的数据行时重定向到新的asp页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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