Link to home
Start Free TrialLog in
Avatar of Rajar Ahmed
Rajar AhmedFlag for India

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of David Robitaille
David Robitaille
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Marcus Keustermans
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

This will make the whole thing more dynamic.
Avatar of Rajar Ahmed

ASKER

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


  • 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>        

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.
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

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.



Avatar of KarinLoos
KarinLoos

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'  ) .


     
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>


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?
thankss
ok mate...
i forgot to put this issue combined with this question itself
soon i ll post this new question ...

Thanks ....
can u plz explain . why  string.concat is used...??
There is many way to concat a string. string.concat is one of them. the & operator is another.
& operator, in VB.net...  string.concat is language insensitive...