Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a variable with datagrid

Status
Not open for further replies.

Stegmite

Programmer
Aug 18, 2004
36
US
I have a datagrid that shows 5 different numbers per record. I've created a Hyperlink column for each, and when they click on the number I want them to go to the same page, no matter what they click on. But I need to pass the number that they clicked on to the next page. How do I do this?
 
post your datagrid HTML code...

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
Do this in your EditItemTemplate:

Code:
<script language='javascript'>
document.write('<a href="javascript:;" onclick="openWin(\'popupNumber.aspx?id=<%# DataBinder.Eval(Container.DataItem, "num1")%>\',\'newWin\',\'width=300,height=225,toolbars=no,scrollbars=no,resizable=yes\');"><%# DataBinder.Eval(Container.DataItem, "num1")%></a>');
	}
</script>

HTH

tigerjade :)

"Always code as if the person who ends up maintaining your code will be a violent psychopath who knows where you live." -- Martin Golding


 
Not sure why you are using document.write() when you could just write the <A tag from the server.

But if you need to a script tag then try this.

<%=Cstr("<scr" & "ipt language='javascript'>") %>
document.write('<a href="javascript:;" onclick="openWin(\'popupNumber.aspx?id=<%# DataBinder.Eval(Container.DataItem, "num1")%>\',\'newWin\',\'width=300,height=225,toolbars=no,scrollbars=no,resizable=yes\');"><%# DataBinder.Eval(Container.DataItem, "num1")%></a>');
}
<% =Cstr("</sc" & "ript>") %>


This fools the ASP interpreter and hides the SCRIPT tags
You may need to replace the = signs with # signs if using this in a data bound control.
 
I don't understand where this goes, so here's my DG code

Code:
<asp:DataGrid id=dgUser runat="server" DataSource="<%# dsTMSUSER_Orig %>" AutoGenerateColumns="False">
					<Columns>
						<asp:BoundColumn DataField="TMSUSER_UID" SortExpression="TMSUSER_UID" HeaderText="User"></asp:BoundColumn>
						<asp:BoundColumn DataField="TMSUSER_MCC1" SortExpression="TMSUSER_MCC1" HeaderText="MCC 1"></asp:BoundColumn>
						<asp:BoundColumn DataField="TMSUSER_MCC2" SortExpression="TMSUSER_MCC2" HeaderText="MCC 2"></asp:BoundColumn>
						<asp:BoundColumn DataField="TMSUSER_MCC3" SortExpression="TMSUSER_MCC3" HeaderText="MCC 3"></asp:BoundColumn>
						<asp:BoundColumn DataField="TMSUSER_MCC4" SortExpression="TMSUSER_MCC4" HeaderText="MCC 4"></asp:BoundColumn>
						<asp:BoundColumn DataField="TMSUSER_RUC" SortExpression="TMSUSER_RUC" HeaderText="RUC"></asp:BoundColumn>
						<asp:BoundColumn DataField="TMSUSER_CO" SortExpression="TMSUSER_CO" HeaderText="Company"></asp:BoundColumn>
						<asp:HyperLinkColumn DataTextField="TMSUSER_MCC1" HeaderText="MCC 1-2" NavigateUrl="schedule_event_reg.aspx"></asp:HyperLinkColumn>
					</Columns>
				</asp:DataGrid>
 
You can put them in place of the boundcolumns:

Code:
<asp:TemplateColumn Header="MCC 1">
<ItemTemplate>
// script to build the link here
</ItemTemplate>
<EditItemTemplate>
// or here if you only want them to see it on edit
</EditItemTemplate>
</asp:TemplateColumn>

There's a great tutorial on using the DataGrid on 4GuysFromRolla.com at
HTH

tigerjade

"Always code as if the person who ends up maintaining your code will be a violent psychopath who knows where you live." -- Martin Golding
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top