Re: Gridview Hyperlink

Hey,

I am using the following web method in my website:-

[WebMethod (Description = "This web method will display threads of specific forum.")]public DataSet GetDataSet(int id)

{

DataSet ds = new DataSet();

string database = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=|DataDirectory|/forum.mdb;Persist Security Info=True";

string queryStr = "SELECT (threads.thread_name) AS Thread, threads.thread_id, COUNT(posts.post_id) AS Replies, (threads.username) AS Author, max(posts.date_posted) AS Last_Post " +

"FROM threads INNER JOIN posts ON threads.thread_id = posts.thread_id WHERE threads.forum_id = '" + id + "' GROUP BY threads.thread_id, threads.thread_name, threads.username";

 

OleDbConnection myConn = new OleDbConnection(database);

OleDbCommand dbCommand = new OleDbCommand(queryStr, myConn);

OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(queryStr, myConn);

myConn.Open();

myDataAdapter.Fill(ds,
"threads");

myConn.Close();

return ds;

}

What this does is brings out details according to a specific forum_id listing all the threads..

When i consume my web method i present it in the form of a gridview..

static DataSet ds;protected void Page_Load(object sender, EventArgs e)

{

Label1.Text += Request.QueryString["name"];

int id = (System.Convert.ToInt16(Page.Request.QueryString["forum_id"]));localhost.Service myws = new localhost.Service();

ds = myws.GetDataSet(id);

GridView1.DataSource = ds;

GridView1.DataBind();

}

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)

{

e.Row.Cells[1].Visible = false;

}

This displays the threads like shown below:-

Thread Replies Author Last_Post
Welcome 2 a 25/04/2009 14:35:24
ASP.Net 1 ole 25/04/2009 14:39:24

What i want to do is have the Name of the Thread as a hyperlink taking users to a page called Posts.aspx with the thread id of the one that has just been clicked.

How can i do this?

Thanks

Regards

0
billy_111
5/4/2009 8:57:18 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

4 Replies
999 Views

Similar Articles

[PageSpeed] 2

I would think you could use the RowDataBound and add the hyperlink as it bind the row in the gridview.

For Example: I did this for a button to delete a column, but you could use the same method to change the data.

// Add a validation javascript to the delete button to make the user confirm they want to delete.
if (e.Row.RowType == DataControlRowType.DataRow)
{
    LinkButton btnDelete = (LinkButton)e.Row.Cells[0].Controls[2];
    btnDelete.OnClientClick = "return confirm('Are you sure you want to delete this entry?')";
}

 Of course this button already exists in my page, so you're wanting to change the data into a hyperlink.

I'm assuming that you have the id field as column 0, and the link field will be column 1, if that's wrong change this accordingly.

if (e.Row.RowType == DataControlRowType.DataRow)

{

//Create a new hyperlink HyperLink hlfDetails = new HyperLink(); //assign the index/id to a variable string id = e.Row.Cells[0].Text; //add the naviation string to the control hlfDetails.NavigateUrl = "Page.aspx?forum_id=" + id; //Remove the data from the current cell e.Row.Cells[1].Controls.Clear(); //Add the hyperlink as it binds. e.Row.Cells[1].Controls.Add(hlfDetails);

}

 I haven't actually tested that but I think that would work.   

0
Janus1313
5/4/2009 10:35:08 PM

Hey,

Thanks for your reply..

Would i need to add something to my existing gridview even though it is bound to the code to the web service?

<asp:GridView ID="GridView1" runat="server" CssClass="tabulardata"

onrowcreated="GridView1_RowCreated" Width="539px">

</asp:GridView>

The code behind for this at the moment is:-

static DataSet ds;protected void Page_Load(object sender, EventArgs e)

{

Label1.Text += Request.QueryString["name"];

int id = (System.Convert.ToInt16(Page.Request.QueryString["forum_id"]));localhost.Service myws = new localhost.Service();

ds = myws.GetDataSet(id);

GridView1.DataSource = ds;

GridView1.DataBind();

}

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)

{

e.Row.Cells[1].Visible =
false;

}

 

0
billy_111
5/4/2009 10:53:13 PM

You'll need to add OnRowDataBound to the Gridview, but other than that I think it'll work

<asp:GridView ID="GridView1" runat="server" CssClass="tabulardata"

onrowcreated="GridView1_RowCreated" OnRowDataBound="GridView1_RowDataBound" Width="539px">

Then the code I have earlier needs to be that function

void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    // Insert what I already posted
}

 
0
Janus1313
5/5/2009 1:32:02 AM

 You'll need to add OnRowDataBound to the Gridview, but other than that I think it'll work

<asp:GridView ID="GridView1" runat="server" CssClass="tabulardata" onrowcreated="GridView1_RowCreated" OnRowDataBound="GridView1_RowDataBound" Width="539px">

Then the function below (with what I put above).

void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
   if (e.Row.RowType == DataControlRowType.DataRow)
    {
        //Create a new hyperlink
        HyperLink hlfDetails = new HyperLink();           
        //assign the index/id to a variable
        string id = e.Row.Cells[0].Text;        
        //add the naviation string to the control  
        hlfDetails.NavigateUrl = "Page.aspx?forum_id=" + id;           
        //Remove the data from the current cell
        e.Row.Cells[1].Controls.Clear();
        //Add the hyperlink as it binds.
        e.Row.Cells[1].Controls.Add(hlfDetails);
    }
}

  
0
Janus1313
5/5/2009 1:38:47 AM
Reply:

Similar Artilces:

GridView
Lets say my data is this in the DB - Column 1     Column 2          Column 3       Column 4        Column5date         <description>            $5                INV                 65date    ...

gridview control in another gridview control
Hi ia have a questioni have a gridview control which contains button in one colum.now my question is i need another gridview to be placed in the  first gidviewso that when i click on the button the second gridview will populate the data.now my question is how to place second gridview in first gridview.or is there any approach like first grid itself acting as parent and child.please help me  Hi sirikalavalapalli:                I think nested gridview will help you. Check this link and it will show you how...

Help Req: !!! :- On Disabling Controls Present inside a Gridview control
Hi All, We have A requirement Where we have disable controls inside a grid.These controls can be textbox, DropDownlist (in TemplateField), ComandField present inside the grid.We have to call a generic method for doing the same .(since it can be done for multiple grid.) PFB the code snippet we use. Which disables all the controls inside the page.The bolded part of the code is used to loop inside a grid view.(Not Working.)Is this ideal way to deal with the requirement.Or can someone suggest be a better way.        public void DisableMe(Page p1, st...

Hyperlink control in Gridview
I have a gridview control with a hyperlink, clickinig on hyperlink opens new page.How can I make the new page open without AddressBar, MenuBar and size 100 / 100 Pixels? <asp:HyperLinkField DataNavigateUrlFields="ReturnPT" DataNavigateUrlFormatString="partsinfo.aspx?partnum={0}"DataTextField="ReturnPT" Target="_blank" HeaderText="ReturnPart"> </asp:HyperLinkField> I think you've to use the javascript like "window.showModalDialog" and add a templateField with LinkButton control embedded instead of hyperlinkField.  However LinkButton hasn't DataNavigateUrlFields and Dat...

Gridview control embedded in another gridview control
I am writing an ambulance crew scheduling application on the web and I need some help completing the last part.  I have an access database that has three tables: user table, shift table (describing the shifts available), and a schedule table (that stores shift by shift_id and user by user_id).  I have a gridview control that will display the available shifts but I cannot get the embedded gridview control that will display the user that is signed up for each shift to display because I cannot figure out how to use the OnRowDataBound method.  I need a simple VB example of how to...

using javascript getting value from textbox when edit button is clicked and both controls are present in gridview control
Hi All using javascript I want to get value  from textbox when edit button is clicked and both controls that is texbox and button are present in gridview control .Alok Hi aloksinha83, Please see this post: http://forums.asp.net/t/1069245.aspx Thanks,Qin Dian TangMicrosoft Online Community SupportPlease remember to mark the replies as answers if they help and unmark them if they provide no help....

Master Details in two seperate GridView Controls
I am simply trying to have a list of people in the top grid control (works fine), then when selected have the second Grid Control show details for that person(not working). Here is what I am trying from the load event: Sub BindData() Dim myConnection As New MySql.Data.MySqlClient.MySqlConnection(System.Configuration.ConfigurationManager.AppSettings("ConnectionSql")) Dim strPersonSQL, strActSQL As String strPersonSQL = "select row_id, first_name, last_name, middle_initial, dsi_id, created, created_by, program_of_study, email from tbl_person" Dim myPerCommand As New MySqlClient.MySqlComm...

Data presentation control in another Data presentation control
 Hello,I want to make a menu with datalist or gridview control.Basically,the menu will be like this,Categories     Sub Categories.For example, for COMPUTING category there will be NOTEBOOKS DESKTOPS etc.There will be a image for CATEGORIES and linkbuttons with Subcategories.If I put a datalist inside a datalist and a link button inside the second datalist visually it satisfies my need.However,CommandArguments come from database to linkbutton.Andwhen one of these command buttons is cliked it must go to proper page.I dont know how to wrie an event_handler ,specifically, for...

Datagrid(.net 1.1) to GridView(.net 2.0) and using the RowUpdating event how to extract the values from the controls.
Ok  This is the settings: I use a Viewgrid with only itemtemplate colums for example. <asp:TemplateField HeaderText="Test"><ItemTemplate><asp:Label id="LBL_Test" text='<%# DataBinder.Eval(Container.DataItem, "Test1") %>' runat="server" meta:resourcekey="LBL_TestResource1"></asp:Label></font></ItemTemplate> <EditItemTemplate><asp:TextBox ID="HDN_Test" Text='<%# DataBinder.Eval(Container.DataItem, "Test1") %>' Runat="server" meta:resourcekey="HDN_TestResource1" /></EditItemTemplate></asp:TemplateField>  The ...

There is a Gridview Control in the tmplate field of another GridView Control.
    For instance,a gridview displays the information of the  students in a class.A table is recording the information except their mark.There is another table recording the mark of the students whose foreign key is the primary key of the previous table.   string strSQLconnection=".................."; SqlConnection sqlCononection=new SqlConnection(strSQLconnection); SqlCommand sqlCommand=new SqlCommand("select * from stuendent where classID=1",sqlConnection); SqlConnection.Open(); SqlDataReader reader=sqlCommand.ExecuteReader(); GridVie...

Gridview control in C#.net
Hi , I am getting error (Object reference not set to an instance of an object.) while trying to update and delete the datas in gridview control. This is the code which i have writen . could anyone assist me on this.     public partial class custom : System.Web.UI.Page {public string connectionstr = System.Configuration.ConfigurationManager.AppSettings["ptcon"]; MySqlConnection conn;MySqlCommand cmd = new MySqlCommand(); DataSet ds = new DataSet();MySqlDataAdapter da = new MySqlDataAdapter();protected void binddata() {conn = new MySqlConnection(co...

RE: GridView Hyperlink If statement
 Hey,How would i refer to a Hyperlink within a gridview by using an If statemt? I want to say If a certain column is selected the do something.                             <asp:TemplateField>                    <ItemTemplate>            <asp:HyperLink ID="HyperLink1" runat=&quo...

How to find a HyperLink Control on Gridview
Hi Guys!, I am trying get to the VB code for my hyperlink on the gridview, I tryed the below code, but no images were showing... any ideas?     Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)        Dim Brand As HyperLink = CType(e.Row.FindControl("Brand"), HyperLink)        If Brand.Text = "1" Then            Brand.ImageUrl = "~/Images/brand1_icon.jpg"        End ...

RE: Gridview Hyperlink #2
Hey, I just wanted to know how to add a link to a gridview when the rows are bound to data according to a web method? I am using this web method:- [WebMethod (Description = "This web method will display threads of specific forum.")]public DataSet GetDataSet(int id) { DataSet ds = new DataSet();string database = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=|DataDirectory|/forum.mdb;Persist Security Info=True"; string queryStr = "SELECT (threads.thread_name) AS Thread, threads.thread_id, COUNT(posts.post_id) AS Replies, (threads.username) AS Author, max(posts....

Web resources about - Re: Gridview Hyperlink - asp.net.presentation-controls

Hyperlink - Wikipedia, the free encyclopedia
A hyperlink points to a whole document or to a specific element within a document. Hypertext is text with hyperlinks. A software system for viewing ...

SA Supreme Court rules Dr Janice Duffy was defamed by Google through its hyperlinks, auto-complete and ...
A FORMER SA Health researcher has won a six-year legal battle against Google, proving she was defamed by the internet giant due to the way it ...

Banned hyperlinks could cost you $11,000 a day
The Australian communications regulator says it will fine people who hyperlink to sites on its blacklist, which continues to be controversially ...

ANALYSIS - Supreme Court hyperlink decision a victory for free speech
A hyperlink by itself should never be seen as 'publication' of other content, the Supreme Court said. But when it comes to libel the court did ...

Review: HyperLink is a great, inexpensive steel bracelet for the Apple Watch
Apple's own stainless steel link bracelet is too expensive for many of us to consider. HyperLink, however, is a less expensive alternative that ...

Apple's 'audio hyperlink' tech can control devices with inaudible sonic pulses
An Apple patent filing published by the U.S. Patent and Trademark Office on Thursday describes a method of encoding hyperlinks into an audio ...

Patent troll sending out invoices for image hyperlinks
A company named Vuestar thinks everyone who links images to pages on the Web …

How Effective Hyperlinks Can Help Your Blog
... link text explain exactly where the link is leading you or does it say something generic like click here ? When I saw Writing Effective Hyperlinks ...

Gmail's Shortcut for Inserting Hyperlinks
... doesn't mean Google shouldn't improve them. Many people complained that Gmail's rich text editor doesn't have a shortcut for inserting hyperlinks ...

Scientology loss keeps hyperlinks legal
The Church of Scientology loses a courtroom battle to compel a Dutch writer and her ISP to remove postings from a Web site, in a ruling that ...

Resources last updated: 12/19/2015 6:31:49 AM