On the bases of user search result for a topic (article) inside the textbox, the grid view is filled with the topic name and the link to the topic for details. Hyperlink
is embedded with the query string variable that contains value for uniquely identifying article in the table
To achieve this we need to create a table in the database and two pages in the designer
Database
In your database create a new table with name
Topic
Having these specification
Column NameData TypeAllow Null
TopicId(PK)nvarchar(50)no
TopicNamenvarchar(50)no
TopicTextnvarchar(MAX)no
Pages
Firstly we need a home page for user to search for a topic
And secondly a topic page for showing the topic content (data) based on user search
Open VS.Net 2005 and from file menu
àselect create new website
Rename the default aspx page to home.aspx
In the design section of home.aspx
1. Drag a Label and a TextBox
2. Drag a Button and make its text to search
3. Drag a GridVeiw and right click over it and select Show Smart Tag if smart tag is not shown by default
4 Then in the Smart Tag of the GridVeiw click the Edit columns link
5. A field wizard will pop, in that make sure
Auto-generate field option is checked
6. In the Available field section
select the HyperLinkField and click the Add button
7. Then Select the HyperLinkField in the selected field section
8.Inside the HyperLinkField Properties section :-
ØIn appearrance section make the text to go
ØIn data section make the DataNagivationUrlFormatString totopic.aspx?TopicId={0}
(Here topic.aspx is the page you wan to redirect and TopicId is the QueryString Variable)
ØIn data section make the DataNavigationUrlField to
TopicId
(This actually specify the value of {0})
Press ok >>>
Your designer should look like this now>>>
Double click the button and inside the code behind file of home.aspxin the button click event function write these lines of code(C# Code)
protectedvoid Button1_Click(object sender,
EventArgs e){// This Creates a new object of connection stringSqlConnection
myconn = new SqlConnection("Your Connection String");//
This Creates a new command object for selecting TopicId and TopicName for user input topic in textboxSqlCommand mycomd =
newSqlCommand("Select TopicId,TopicName From Topic Where TopicName=@tn", myconn);mycomd.CommandType
= CommandType.Text;mycomd .Parameters .Add (newSqlParameter("@tn",SqlDbType.NVarChar ,50));//
search for user topic in TopicNamemycomd.Parameters["@tn"].Value = TextBox1.Text;
//create a new object of SqlDataAdapter for filling
up the DataSetSqlDataAdapter
myadp = newSqlDataAdapter(mycomd);DataTable dt =
newDataTable();
// make a new empty datatabletry{myconn.Open();myadp.Fill(dt);if
(dt.Rows.Count != 0)//check is there any row return by our query{GridView1.DataSource
= dt; // filling the grid with search resultPage.DataBind();}else{Label1.Text
= "No result";}}catch
( Exception exe){Label1.Text =exe.Message.ToString();
// if there is some error in execution}
}
After this from the Solution Explorer add a new Web Form and Rename it to topic.aspx
In the design section of page drag a GridVeiw
A smart tag will be shown and that choose new Data Source
Choose your database and select all fields from the topic table and Click the
WHERE button .You will see Add WHERE clause wizard
Inside that
Select TopicId
From DropdownList of column Select QueryString
From Dropdownlist of SourceIn QueryString Field textbox
write TopicId
Click add then ok and then finally click finish
You are done…see-working screenshot of the application
Member
690 Points
149 Posts
Filling a Grid View with a Hyperlink to an article based on the User Search
Jun 12, 2007 01:12 AM|push_the_envelope|LINK
Plz give rating on this >>
Introduction
On the bases of user search result for a topic (article) inside the textbox, the grid view is filled with the topic name and the link to the topic for details. Hyperlink is embedded with the query string variable that contains value for uniquely identifying article in the table
To achieve this we need to create a table in the database and two pages in the designer
Database
In your database create a new table with name TopicHaving these specification
Column Name Data Type Allow Null
TopicId (PK) nvarchar(50) no
TopicName nvarchar(50) no
TopicText nvarchar(MAX) no
Pages
Firstly we need a home page for user to search for a topic
And secondly a topic page for showing the topic content (data) based on user search
Open VS.Net 2005 and from file menu àselect create new website
Rename the default aspx page to home.aspx
In the design section of home.aspx
1. Drag a Label and a TextBox
2. Drag a Button and make its text to search
3. Drag a GridVeiw and right click over it and select Show Smart Tag if smart tag is not shown by default
4 Then in the Smart Tag of the GridVeiw click the Edit columns link
5. A field wizard will pop, in that make sure Auto-generate field option is checked
6. In the Available field section select the HyperLinkField and click the Add button
7. Then Select the HyperLinkField in the selected field section
8.Inside the HyperLinkField Properties section :-
Ø In appearrance section make the text to go
Ø In data section make the DataNagivationUrlFormatString to topic.aspx?TopicId={0}
(Here topic.aspx is the page you wan to redirect and TopicId is the QueryString Variable)
Ø In data section make the DataNavigationUrlField to TopicId
(This actually specify the value of {0})
Press ok >>>
Your designer should look like this now>>>
Double click the button and inside the code behind file of home.aspx in the button click event function write these lines of code(C# Code)
protected void Button1_Click(object sender, EventArgs e){// This Creates a new object of connection stringSqlConnection myconn = new SqlConnection("Your Connection String"); // This Creates a new command object for selecting TopicId and TopicName for user input topic in textbox SqlCommand mycomd = new SqlCommand("Select TopicId,TopicName From Topic Where TopicName=@tn", myconn); mycomd.CommandType = CommandType.Text;mycomd .Parameters .Add (new SqlParameter("@tn",SqlDbType.NVarChar ,50)); // search for user topic in TopicNamemycomd.Parameters["@tn"].Value = TextBox1.Text; //create a new object of SqlDataAdapter for filling up the DataSet SqlDataAdapter myadp = new SqlDataAdapter(mycomd);DataTable dt = new DataTable(); // make a new empty datatable try{myconn.Open();myadp.Fill(dt);if (dt.Rows.Count != 0)//check is there any row return by our query{ GridView1.DataSource = dt; // filling the grid with search resultPage.DataBind(); }else{Label1.Text = "No result";}}catch ( Exception exe){Label1.Text =exe.Message.ToString(); // if there is some error in execution}}
After this from the Solution Explorer add a new Web Form and Rename it to topic.aspx
In the design section of page drag a GridVeiw
A smart tag will be shown and that choose new Data Source
Choose your database and select all fields from the topic table and Click the WHERE button .You will see Add WHERE clause wizard
Inside that
Select TopicId From DropdownList of column Select QueryString From Dropdownlist of SourceIn QueryString Field textbox write TopicIdClick add then ok and then finally click finish
You are done…see-working screenshot of the application
plz plz do give rating on this >>>