Pass "calendar.selectedvalue" to querystring from gridview

I wanted to transfer calendar1.Selecteddate

in query string

from gridview

on one page to another gridview

(I wrote sqlquery

in this gridview

) on another page. As you can see from the code below, I tried to pass it, but it didn't work. Can anyone tell me how to pass the selected date from calendar

toquery string

      <asp:HyperLinkField DataNavigateUrlFields="LocalIP" 
                DataTextField="LocalIP" HeaderText="User" />



source to share

3 answers

One solution is to create your url string in code instead of creating it in markup.

Override the RowDataBound method in the GridView and create the hyperlink programmatically:

protected override gv1_RowDataBound(object sender, GridViewRowEventArgs e)
  HyperLink hl = new Hyperlink();
  hl.NavigateUrl = string.Format("DailyResults.aspx?Terms={0}&column=LocalIP&startdate={1}", localIp, Calendar1.SelectedDate.Date.Date.ToShortDateString());
  .. set other hyperlink fields ..


Hope it helps!



In the example you provided, it will treat this calendar part of the string as a literal and pass in the exact value you typed. To get the data, you will need to do something similar to:

<asp:HyperLinkField DataNavigateUrlFormatString="<%=GetSelectedDate()%>....


where is the method for the code behind the class (or you can use a property) that creates the string you intend, including the {0} placeholder for the data field bound to LocalIP.



I am assuming the selected calendar value has not changed since the rendering of the gridview.

<asp:HyperLinkField DataNavigateUrlFields="LocalIP" 
     DataNavigateUrlFormatString='<%# "DailyResults.aspx?Terms={0}&column=LocalIP&startdate=" + Calendar1.SelectedDate.Date.Date.ToShortDateString() %> DataTextField="LocalIP" HeaderText="User" />




All Articles