且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在asp.net中单击数据网格视图的数据行时重定向到新的asp页面

更新时间:2023-11-23 10:18:58

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.