Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Comments
What have you tried? Where is the issue?

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
 
Share this answer
 
You can do it directly in the grid itself by combining a HyperLinkField with a DataNavigateUrlField:

ASP.NET
<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>
 
Share this answer
 
v3
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900