0

I have a column in grid which is of hyperlink type and when I click, it should take me URL on basis of JavaScript function. Now my question is how should I pass database column name as parameter into JavaScript function. I tried something which is not fruitful.

<ItemTemplate>

     <td colname="time_type" >
   <a ><%#DataBinder.Eval(Container.DataItem, "TYPE_SEQ")%></a> 

         </td>


</ItemTemplate>

function Time_type(<%# Eval( "TIME_TYPE_INDICATOR" ) %>,<%# Eval( "TYPE_SEQ" ) %>){
  var url;       
if (<%# Eval( "INDICATOR" ) %> == 'O'){
url= www.something.com/<%# Eval( "TYPE_SEQ" ) %>?;

}
else if(<%# Eval( "INDICATOR" ) %> == 'T'){
url= www.something.com/<%# Eval( "TYPE_SEQ" ) %>?;

}
}

The function here is taking 2 database columns as parameters and based on one parameter other parameter is used as query string in URL. My javascript function is not working and I know it is not right way to pass paramaters like this.Please help. **Also please show me how to call this function on hyperlink click **

1 Answer 1

0

I might sound stupid but why use so difficult names for function(someName,someOtherName)... For example doesn't functions work like this:

function someFunction(val1,val2){
    var troll = val1+val2;
    return troll;
}
var temp = someFunction(1,2); // temp is now 3. So here is the right way to call functions and pass it parameters.

I'm still quite new to coding in general but I think from hyperlink it goes like this:

<a onClick='someFunction(someValue,someOtherValue);'></a>

Also I would put in quotes when assigning variable: url = "www.something.com/"+someVariable;

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

5 Comments

I know this works, but my question is how to pass database column values in to this function...:)
what database are you using?
have you tried this: <a onClick='Time_type(<%#DataBinder.Eval(Container.DataItem, "TYPE_SEQ")%>);'></a>
stackoverflow.com/questions/12850327/… this came up when searching. Might be of use to you
stackoverflow.com/questions/3139678/… Another post on the matter

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.