This is a bit embarassing, but I just can't seem to figure it out...
I have a simple datagrid that uses a calendar control to display information by a selected date. One field of the datagrid is a hyperlink column that allows the user to see additional details about each item in a pop-up window.
The pop-up window is another simple datagrid, using a code-behind to look-up the extra information.
The (Access) database uses separate tables for each month of the year (0105, 0205, etc.) and which table we need to read is determined by the selected month of the calendar control.
But I cannot figure out how to pass the month to the code behind to use the correct table in the query for detailed information.
Here is the primary datagrid hyperlink column:
<asp:HyperLinkColumn
DataTextField="Title"
DataNavigateUrlField="ResvNum"
DataNavigateUrlFormatString="javascript: var popWindow=window.open('event-detail.aspx?id={0}', 'popWindow'); popWindow.focus();"
Target="_self"
HeaderText="Title">
</asp:HyperLinkColumn>
[ResvNum is the primary key for each table, Access auto-increment]
And here is the code-behind (minus 'Import' statements):
public class Detail : Inherits System.Web.UI.Page
public eventDetail as DataGrid
private sub Page_Load (sender as object, e as System.EventArgs)
dim _id as String = Request.QueryString("id")
dim strSQL as String = "SELECT [0805].ResvNum, [0805].Dy, [0805].BegTime, [0805].Ending, [0805].EventType, [0805].Title, [0805].Person, Facility.BldgName, Facility.Abbrev " & _
"FROM Facility LEFT JOIN [0805] ON Facility.FacNum = [0805].Room " & _
"WHERE [0805].ResvNum = " & _id & ""
eventDetail.DataSource = getDetail(strSQL)
eventDetail.DataBind()
end sub
private function getDetail (strSQL as string) as oleDbDataReader
dim dtrDetail as oleDbDataReader
dim detailConn as oleDbConnection = new oleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & server.mappath("../TESTDATA/TEST.mdb") & ";")
dim detailCmd as oleDbCommand = new oleDbCommand(strSQL, detailConn)
detailCmd.Connection.Open()
dtrDetail = detailCmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
return dtrDetail
end function
end class
This is hard-coded to read the data table for August 2005. It is the [0805] I need to dynamically change depending on the selected date.
How do I pass that date to the code-behind query?
Thanks,
Tinker
<ItemTemplate>
<asp:HyperLink id="linkColumn1" runat="server"Text='<%# DataBinder.Eval(Container,"DataItem.MyDataField") %>'Target=_blank NavigateUrl='<%#"event-detail.aspx?id="& DataBinder.Eval(Container,"DataItem.MyDataField") & "?other_param=" & DataBinder.Eval(Container,"DataItem.MyOtherDataField") %>'>
</asp:HyperLink>
</ItemTemplate>
HTH
uncleb --
Thank you for this, and it makes sense -- but the file identifier is not a dataitem. It is derived from the calendar control as
qryFile = calDate.SelectedDate.ToString("MMyy")
and used in the query as
strSQL = "SELECT ResvNum, Person FROM qryFile"
So I can't pass it as part fo the dataitems collection.
Or -- at least -- I still don't know how to identifiy it to send it on to the code-behind.
If there's a refernce article, please send me off to read it.
Thanks again,
<ItemTemplate>
<asp:HyperLink id="linkColumn1" runat="server"Text='<%# DataBinder.Eval(Container,"DataItem.MyDataField") %>'Target=_blank NavigateUrl='<%#"event-detail.aspx?id="& DataBinder.Eval(Container,"DataItem.MyDataField") & "?qryFile=" &calDate.SelectedDate.ToString("MMyy") %>'>
</asp:HyperLink>
</ItemTemplate>
if the calendar is on the same page and loaded with the right date . Ifnot, I would use a button - then in the click event set the urlstringusing the datagrid datakeyfield and the calDate
HTH
YES! This works!
Thanks for hanging-in and guiding me through this. Appreciate it HUGELY.
Okay, I spoke too soon...
<asp:HyperLink id="linkColumn1" runat="server"
Text = '<%# DataBinder.Eval(Container,"DataItem.Title") %>'
NavigateUrl = '<%# "event-detail.aspx?qryFile = " & calDate.SelectedDate.ToString("MMyy") & "& ?id = "& DataBinder.Eval(Container, "DataItem.ResvNum") %>'
Target = _blank>
</asp:HyperLink>
Does not seem to be passing the second variable to the code behind, regardless of whether I rearrange the variable to make "id" first or second.
In the code-behind, I added:
trace.warn ("Incoming File " & Request.QueryString("qryFile "))
trace.warn ("Incoming ID " & Request.QueryString("id"))
dim _qryFile as String = Request.QueryString("qryFile ")
dim _id as String = Request.QueryString("id")
trace.warn ("Query File " & _qryFile)
trace.warn ("Query ID " & _id)
And these are the results of the trace.warnings:
Incoming File = 0805
Incoming ID =
Query File = 0805
Query ID =
(Reversing the order in which I pass the variables -- putting "id" first -- passes the ID, but not the qryFile date)
What am I doing wrong in the HyperLink NavigateUrl statement?
try..
NavigateUrl = '<%# "event-detail.aspx?qryFile=" &calDate.SelectedDate.ToString("MMyy") & "?id=" &DataBinder.Eval(Container, "DataItem.ResvNum") %>'
I took out an " &" and got rid of some spaces - no spaces in querystrings.
Well, you're still haniging in with me, and I appreciate it.
Didn't work. When I remove the '&' in the navurl, the variables are passed as a single variable, and the trace showsFileID = 0805?id=1769andResvNum=. I did remove all of the blank spaces, however.
I'm not sure what I'm seeing here, but maybe this will help: when the cursor is over the link on the (first page) data grid, the IE status bar shows that the link is
events-detail.aspx?qryFile=0805&?id=1120 -- which is a valid record id (ResvNum) in an existing table, and that LOOKS right to me. But the "id" is still not making it to the code-behind...
I'm kind of at a loss with this, and I'm just not smart enough to see what I'm doing wrong.
If there's anything more I can add to this thread that might help pinpoint my error, let me know?
Sorry , my fault
try..
NavigateUrl = '<%# "event-detail.aspx?qryFile=" &calDate.SelectedDate.ToString("MMyy") & "&id=" &DataBinder.Eval(Container, "DataItem.ResvNum") %>'
there is only one question mark in a querystring- params are seperated by "&"
So was it all just a test to see if I'd finally admit how dumb I am? 8-)
The two "?" was the problem; it is all working. I've been staring at it for three days and didn't see it.
Again, many thanks.
0 comments:
Post a Comment