1

Hi this is my row in gridview in ASP.Net

<ItemTemplate>
<a id="aOpen" onclick="javascript:Open(<%#((DataRowView)Container.DataItem)['DocTypeCode'] %>)" >A_<%#((DataRowView)Container.DataItem)["Id"] %></a>
</ItemTemplate>

Here is my javascript

<script type="text/javascript">
function Open(var id) {
        var strPageURL = '<%= ResolveClientUrl("~/View.aspx?id="+id) %>';
        OpenCustomDialogWithRefresh(strPageURL, 750, 500, "View Document Type");
        return true;
}
</script>

I would like to pass the Id value from the gridview to the javascript and open a new page with query string. How should I try ? Mine does not work.

2 Answers 2

2

I think you want simply:

<%# Eval("DocTypeCode") %>


onclick='javascript:Open(<%# Eval("DocTypeCode") %>)" >A_<%# Eval("Id") %></a>

Also note that this

<a id="aOpen"

is a huge problem, since all dom elements must have unique ids

Sign up to request clarification or add additional context in comments.

7 Comments

@kevin - you mean how should you assign unique ids to your anchors? Unless you actually need to reference these anchors in a script by id somewhere, I would say just leave off the id altogether
How about <input type="button" value="<%#((DataRowView)Container.DataItem)["DocTypeCode"] %>" onclick="javascript:Open()" /> ?
I don't know how to pass the value to the javascript and put the value as a query string.
@kevin - you can just add the values you need to your querystring using Eval like in my answer above
@kevin - just start slow. See if you can get the content output just as plain text in your ItemTemplate. then slowly add in the other stuff around it -- like your anchors with querystrings and such.
|
1

I think you should try this below code:

onclick="javascript:Open('<%#Eval("DocTypeCode") %>')"

is a syntax problem, I should add the character ''

1 Comment

I tried like this <img src="~/Imgs/GroupJoin.png" id="imgJoin" alt="Invite" runat="server" onclick="javascript:PostRequest('<%#Eval("ID") %>')" /> but i am getting a syntax error. its inside a gridview item template

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.