Query String Doubt

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

LVL 18
Rajar AhmedConsultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David RobitailleAnalyst ProgrammerCommented:
  1. dont use <a href, use a
    <asp:HyperLink
  2. set
    NavigateUrl='<%# string.concat("south.aspx?cid=", eval("cid").tostring()) %>'
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
keustermansCommented:
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
keustermansCommented:
This will make the whole thing more dynamic.
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Rajar AhmedConsultantAuthor Commented:
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
Rajar AhmedConsultantAuthor Commented:

  • 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
David RobitailleAnalyst ProgrammerCommented:
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
Rajar AhmedConsultantAuthor Commented:
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
David RobitailleAnalyst ProgrammerCommented:
try Eval
0
Rajar AhmedConsultantAuthor Commented:
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
David RobitailleAnalyst ProgrammerCommented:
0
KarinLoosCommented:
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
Rajar AhmedConsultantAuthor Commented:
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
David RobitailleAnalyst ProgrammerCommented:
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
Rajar AhmedConsultantAuthor Commented:
thankss
0
Rajar AhmedConsultantAuthor Commented:
ok mate...
i forgot to put this issue combined with this question itself
soon i ll post this new question ...

Thanks ....
0
Rajar AhmedConsultantAuthor Commented:
can u plz explain . why  string.concat is used...??
0
David RobitailleAnalyst ProgrammerCommented:
There is many way to concat a string. string.concat is one of them. the & operator is another.
0
David RobitailleAnalyst ProgrammerCommented:
& operator, in VB.net...  string.concat is language insensitive...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.