?
Solved

Query String Doubt

Posted on 2008-11-20
18
Medium Priority
?
636 Views
Last Modified: 2013-12-17
I ve a  grid view which has linkbutton(edittemplate) consists of cname on clicking this ,
,i need to pass cid value, to <a href="south.aspx?cid=????"> Like that to all link....
how can i do it..

table 1 ( table structure)
cid int primary key
cname varchar


<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <link href="style/sample.css" rel="stylesheet" type="text/css" />
</head>
<body>
 
    <form id="form1" runat="server">
    <div id="container">
  
    <div id="left">
 
 
<%  
                    string constr = ConfigurationManager.AppSettings["cons"];
                    SqlConnection con = new SqlConnection(constr);
                    string cmd = "Select * from citytable";
                    SqlDataAdapter da = new SqlDataAdapter(cmd, con);
                    DataSet ds = new DataSet();
                    da.Fill(ds);
                    GridView1.DataSource = ds;
                    GridView1.DataBind();
          %>
                                <a href="south.aspx?cid='Doubt How to get cid'"><img src="images/south_indian.gif" border="0" /></a></td>
							<td width="25%">
                                <a href="North1.aspx?cid='Doubt How to get cid'"><img src="images/north_indian.gif" border="0"/></a></td>
						</tr>
						<tr>
							<td>
                                <a href="udipi.aspx?cid='Doubt How to get cid'"><img src="images/udipi.gif" border="0" /></a></td>
							<td>
                                <a href="chettinad.aspx?cid='Doubt How to get cid'"><img src="images/chettinad.gif" border="0" /></a></td>
						</tr>
						<tr>
							<td>
                                <a href="hyderabad.aspx?cid='Doubt How to get cid'"><img src="images/hyderabad.gif" border="0"/></a></td>
							<td>
                                <a href="kerala.aspx?cid='Doubt How to get cid'"><img src="images/kerela.gif" /></a></td>
						</tr>
						<tr>
							<td>
                                <a href="american.aspx?cid='Doubt How to get cid'"><img src="images/american.gif" border="0"/></a></td>
							<td>
                                <a href="chinese.aspx?cid='Doubt How to get cid'"><img src="images/chinese.gif" border="0" /></a></td>
						</tr>
					</table>
 
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Style="left: 8px;
            position: relative; top: 112px">
            <Columns>
                <asp:TemplateField HeaderText="City Name">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        &nbsp;<asp:LinkButton ID="LinkButton1" Text='<%# Bind("city") %>' runat="server" Style="position: relative">LinkButton</asp:LinkButton>
                        
                    </ItemTemplate>
                </asp:TemplateField>

Open in new window

0
Comment
Question by:Rajar Ahmed
  • 8
  • 7
  • 2
  • +1
18 Comments
 
LVL 18

Accepted Solution

by:
David Robitaille earned 2000 total points
ID: 23003495
  1. dont use <a href, use a
    <asp:HyperLink
  2. set
    NavigateUrl='<%# string.concat("south.aspx?cid=", eval("cid").tostring()) %>'
0
 
LVL 7

Expert Comment

by:keustermans
ID: 23003529
What you can do here add a column to Table1 that will hold the pagename that you link needs to point to as well as the image path that you want to load.

cId              cName              link                            imagePath
1                Myname            south.aspx?cid=      images/south_indian.gif

select cid, link+convert(varchar,cid) as link, imagePath from ......

this will geneerate a resultset as follows

1     MyName  south.aspx?cid=1   images/south_indian.gif
     

Fill a dataset with this data bind to a repeater and use the repeater to create the links for you:

your Item template should look something like this:

<ItemTemplate>
<td><a href="<%# DataBinder.Eval(Container.DataItem,"link") %>"><img src="<%# DataBinder.Eval(Container.DataItem,"imagePath") %> "/></a></td>
</ItemTemplate>

Resource on how to use a repeater control: http://www.devhood.com/view_source.aspx?source=/news/news_sub.aspx

0
 
LVL 7

Expert Comment

by:keustermans
ID: 23003561
This will make the whole thing more dynamic.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 23003564
I got followin errors  

 'string' does not contain a definition for 'concat'    
  The name 'eval' does not exist in the current context  


<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='<%# string.concat("south.aspx?cid=", eval("cid").tostring()) %>'>HyperLink</asp:HyperLink>	    

Open in new window

0
 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 23003580

  • Now only this error
  • The name 'eval' does not exist in the current context
<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='<%# string.Concat("south.aspx?cid=", eval("cid").ToString()) %>'>HyperLink</asp:HyperLink>        

0
 
LVL 18

Expert Comment

by:David Robitaille
ID: 23003603
well, i dident saw it was outside the gridview.
the link must be inside a binded control like a repeter, a gridview or a detailview.
0
 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 23003673
i binded inside the gridview i got the same error ,

The name 'eval' does not exist in the current context

 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Style="left: 8px;
            position: relative; top: 112px">
            <Columns>
                <asp:TemplateField HeaderText="City Name">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        &nbsp;<asp:HyperLink ID="LinkButton1" Text='<%# Bind("city") %>' NavigateUrl='<%# string.Concat("south.aspx?cid=", eval("cid").ToString()) %>' runat="server" Style="position: relative">Hyper</asp:HyperLink>
                                            </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Style="left: 8px;
            position: relative; top: 112px">
            <Columns>
                <asp:TemplateField HeaderText="City Name">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        &nbsp;<asp:HyperLink ID="LinkButton1" Text='<%# Bind("city") %>' NavigateUrl='<%# string.Concat("south.aspx?cid=", eval("cid").ToString()) %>' runat="server" Style="position: relative">Hyper</asp:HyperLink>
                                            </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

Open in new window

0
 
LVL 18

Expert Comment

by:David Robitaille
ID: 23003700
try Eval
0
 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 23003709
hi keustermans,

Sorry mate , i had used cid field for many table , if i change the structure now i have to delete some important data's which are used by other tables.



0
 
LVL 18

Expert Comment

by:David Robitaille
ID: 23003747
0
 
LVL 13

Expert Comment

by:KarinLoos
ID: 23003801
Well you could use the page_load event, and in this event pick up the link and dynamically set the href.
pretty simple really. If woud however REQUIRE that you put the runat='server'  attribute to each of your links as well as giving each tag a unique id  ( ie id='abc'  ) .


     
0
 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 23003822
Hi , it works....
Now i want that City in a label control, so that i can say city from this cid  page...

Text='<%# Bind("city") %>' ---> In A label control in a page....to display its details ..

    <ItemTemplate>
                         <asp:HyperLink ID="LinkButton1" Text='<%# Bind("city") %>' NavigateUrl='<%# string.Concat("south.aspx?cid=", eval("cid").ToString()) %>' runat="server" Style="position: relative">Hyper</asp:HyperLink>
                                            </ItemTemplate>


0
 
LVL 18

Expert Comment

by:David Robitaille
ID: 23003876
it`a the same thing, just use a asp.label. but don`t "bind" label, use Eval.
if it`a another page, use response.Querystring("cid") in the page load or wherever.
But, did you think to ask another question?
0
 
LVL 18

Author Closing Comment

by:Rajar Ahmed
ID: 31518653
thankss
0
 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 23004048
ok mate...
i forgot to put this issue combined with this question itself
soon i ll post this new question ...

Thanks ....
0
 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 23004116
can u plz explain . why  string.concat is used...??
0
 
LVL 18

Expert Comment

by:David Robitaille
ID: 23004145
There is many way to concat a string. string.concat is one of them. the & operator is another.
0
 
LVL 18

Expert Comment

by:David Robitaille
ID: 23004152
& operator, in VB.net...  string.concat is language insensitive...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month9 days, 15 hours left to enroll

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question