Home » .Net FrameworkRSS

Pass XSL "Currently Selected" Value via Query String

Hi,

I have a DVWP with an ID column, that's connected to other webparts on the page to filter their values accordingly.   I also have a "Print" button that opens a custom ASP page that's essentially a print-friendly single item data view. 

How do I pass the "selected item" value to the URL when a user hits the print button?

I've already set up the "ID" parameter and filters on the target page, just need to know how to get the value info from the list ID field inserted into the URL upon button click. 

Thanks in advance

 

10 Answers Found

 

Answer 1

Hi,

How did you open the 'print' page? Did you open the page with javascript or redirec to it?

Can you get the id of the selected  item?

 

Answer 2

Thanks for responding.

I'm redirecting to it using the default URL settings on the interactive button (which I created using SP Designer). I don't write code so that was my best option.

The page's "selected ID" is being shared to other web parts via web part connections. 

Problem is I don't know how to collect the "selected ID" (is it something like <xsl:value-of... ?) and have it inserted into the URL of the target page.   Nothing I've tried so far works, so clearly I'm missing something...

 

Answer 3

Hi,

Can you share some code ? It's better if you can.

Thanks.

 

 

Answer 4

Sorry, here is the code for a cell in the "ID" column. Users select an ID to filter the source page by that project ID. I want to pass  the value of whatever ID the user selects to the target page via query  string (when "print" button is clicked).

<td class="style79" style="width: 28px; height: 17px">
    <span>
    <span class="style79"><a target="_self">
    <xsl:attribute name="href">
        <xsl:variable name="cursel">dvt_curselkey={
            <xsl:call-template name="dvt.gencurselkey">
                <xsl:with-param name="RowPath" select="." />
            </xsl:call-template>
            
            }</xsl:variable>
        <xsl:variable xmlns:xsl="http://www.w3.org/1999/XSL/Transform" name="fields">@ID=<xsl:value-of select="ddwrt:ConnEncode(string(@ID))" /></xsl:variable>
        <xsl:text>javascript:</xsl:text>
        <xsl:value-of select="ddwrt:GenFireConnection(concat('g_7ce3bd52_aa03_4948_b05f_3f53fb62678b#g_b55bd7a9_6f62_4c62_8fb6_251fbdef3546#g_17a25901_cfc4_4f74_a731_256654dbd92a#g_45281526_0a1c_454f_943f_fcc05bbdc0e8#g_f0d8866a_0b79_49b4_b65b_881b2e49cb15#g_cd864f7e_0b43_4b05_b359_25a09c982e63#g_73283a41_8736_4bd3_808c_6abc5135ac58*',$fields),string($cursel))"></xsl:value-of>
    </xsl:attribute>
    <xsl:attribute name="style">
        <xsl:if test="$CurrentRowKey = $dvt_curselkey">font-weight: bold;</xsl:if>
    </xsl:attribute>
    <xsl:value-of select="format-number(@ID, &quot;###0.;-###0.&quot;)" />
    </a></span></span></td>

 

Answer 5

Hi,

I am sorry to response too late.

Because the DataView webpart doesn't allow us to select one item. So we have to find a workaround to get the id of the selected  item.

We can add a radio button to select one item and at the same time we can assign the id value of the selected item to a hidden field.

Then we can get the value when we open a new window by clicking the 'print' button.

You can refer to the following solution.

<tr valign="top" bgcolor="#808080" style="color: #FF0000">
				<xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
					<th class="ms-vh" width="1%" nowrap="nowrap"></th>
				</xsl:if>
				<th>Selected</th>
				<th class="ms-vh" nowrap="" style="display:none">ProductID</th>
				<th class="ms-vh" nowrap="">ProductName</th>
				<th class="ms-vh" nowrap="">QuantityPerUnit</th>
				<th class="ms-vh" nowrap="">UnitPrice</th>
				<th class="ms-vh" nowrap="">UnitsInStock</th>
			</tr>
.......................................................

<tr>
<td><input name="Radio1" type="radio" onclick="javascript:document.getElementById('hiddenfield1')(this.parentElement.nextSibling.innerText)" /></td>
			<td class="ms-vb" style="display:none">
				<xsl:value-of select="ProductID"/>
			</td>
			<td class="ms-vb">
				<xsl:value-of select="ProductName"/>
			</td>
			<td class="ms-vb">
				<xsl:value-of select="QuantityPerUnit"/>
			</td>
			<td class="ms-vb">
				<xsl:value-of select='format-number(UnitPrice,"0") '/>
			</td>
			<td class="ms-vb">
				<xsl:value-of select="UnitsInStock"/>
			</td>

</tr>

Then you can open the 'ASP'page with javascript method 'window.open()'. You can get the id of the selected item from that hiden field to construct a url. 


Microsoft Online Community Support
 

Answer 6

Thanks alot for your response, however it's not exactly what I need.  Please bare with me:

I'm already able to "select" the appropriate info from the DVWP, so I don't need a radio button.

I have a DVWP with an "ID" column (code above). When an ID is selected  from that column, it already populates a value in the "Project ID" cell in a single item data form on the same page (accomplished via web part connections). 

Project ID:   32

Here is the code for the cell containing the Project ID value ("32" in the above example):

 <td class="style102" style="width: 82%; height: 16px;">
   <strong><a href="http://infonet.tnb.com/sites/ProjectServices/Warehouse/Lists/Projects/EditForm_buttons.aspx?ID={@ID}"
   onclick="GoToLink(this);return false;"
   target="_self"><span class="style80"><xsl:value-of select="@Title" /></span></a></strong></td>

 

What I can't figure out (cause I'm new at passing variables in the query  string in SharePoint/ASP) is how to construct the URL based on the selected "Project ID" value.  I need clear, step by step instructions on how to do this.

Thanks again for providing assistance.

 

Answer 7

Hi,

You mentioned that you could get the selected  Project ID value.

So I assume that the value is '123' and the url of the page which would be opened by clicking the 'print' is something like 'http://sap/pages/pageName'.

Then you can construct the url like the url ''http://sap/pages/pageName?Id=123'.

We can open the page with 'window.open' .

Regarding the 'window.open' method, you can visit the following website.

http://wap.w3schools.com/jsref/met_win_open.asp

 

Answer 8

Sorry, I feel I'm doing a bad job asking the right questions (or I'm just not fully understanding the solution provided).  It is probably because I'm new to development, ASP.NET, and to dealing with code.

Here is my best shot at restating my need.

When a user selects an ID, I see it in the Project ID field (code above from yesterday), however I don't know what part of the code represents the variable, how to grab that variable value from the SP code (based on what was selected  on the page), or what syntax to use to construct the URL with the variable as part of it.

I've tried entering various combinations (in code view) that did not work:

<a href=http://myURL.aspx?ID={@ID}>

<a href=http://myURL.aspx?ID={@Title}>

<a href=http://myURL.aspx?ID= + xsl:value-of select="@Title">

So I'm obviously doing something wrong.  I don't know how/where to get the selected project ID value, or how to put it in the URL of the button, so that the selected value will be passed to the target page.

Please help, and thanks again.

 

Answer 9

Hi,

I don't think the item of DataView webpart can be selected  in default.

So I have to add a selected column with a radio button to select the item and get the id.

If I made a mistake, could you tell me how to select one item with your mouse?

If you couln't, we have to add the radio column to get the project id of the selected item.

After storing the project id in a hidden field with the solution above, we can get the value with 'document.getElementById('hiddenfieldId').value'.

Then you can define the 'onclick' method for the 'print' button to open a new page with 'window.open'.

You can find more detail information from my post above.

 

Answer 10

Ok, I'll see if I can make it work with the hidden field and other info you've provided.

FYI, I'm able to select the ID value in the DataView web part because it's connected to other web parts.  On the last page of the connection dialogue, it prompts you to choose what data element to add the hyperlink to, as well as how to indicate it's been selected  (bold, etc).

Thanks again for all your help.

 

 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Tech Videos   |   Follow us on Twitter