1

Im working in ASP.net with C#, i need help to correct or have an approach to get what i need. Im working with gridview, data select a set of data that will be used depending of its primarykey into another table.

On the runtime on client side, i need to collect on the onclick event, the sid column of each row and put it into a hidden field. However, the code below, is not working for me as the <%#eval("sid"); %>! is being read as a string, than the current row value.

What i need is the checkbox once clicked alert(5) instead of alert('<%#eval("sid"); %>!'); that is what is currently doing.

<Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:CheckBox runat="server" ID="cbSelect" onclick="javascript:alert('<%#eval("sid"); %>!');"/>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:HyperLinkField DataTextField="nombre" NavigateUrl="http://www.google.com" HeaderText="direccion"/>
            <asp:BoundField DataField="sid" HeaderText="sid" InsertVisible="False" 
                ReadOnly="True" SortExpression="sid" />
            <asp:BoundField DataField="nombre_archivo" HeaderText="nombre_archivo" 
                SortExpression="nombre_archivo" />
</Columns>

If further information is needed, please ask what you need me to add to the question.

3 Answers 3

1

Try this, worked for me:

<asp:CheckBox runat="server" ID="cbSelect" onclick='<%# "javascript:alert(" + Eval("sid") + " );" %>'/>
Sign up to request clarification or add additional context in comments.

Comments

0

I believe Eval is case-sensitive, and you don't need that semi-colon:

 <%# Eval("sid") %>

1 Comment

I tried this solution but, it ouput <%# Eval("sid") %> as html entities, Thank's
0

Try changing your code to this. And your Eval() was actually eval() which is invalid.

<Columns>
 <asp:TemplateField>
  <ItemTemplate>
   <asp:CheckBox runat="server" 
        ID="cbSelect" 
    onclientclick='<%#string.Format("javascript:alert('{0}');",Eval("sid"))%>'/>
   </ItemTemplate>
  </asp:TemplateField>
 <asp:HyperLinkField DataTextField="nombre" 
     NavigateUrl="http://www.google.com" HeaderText="direccion"/>
  <asp:BoundField DataField="sid" HeaderText="sid" InsertVisible="False" 
                ReadOnly="True" SortExpression="sid" />
      <asp:BoundField DataField="nombre_archivo" HeaderText="nombre_archivo" 
                SortExpression="nombre_archivo" />
</Columns>

2 Comments

I tried this approach with no sucess, as it sends and error, for the subsequent controls. Thanks.
I didnt copied the error but what it says, is tht the <asp:CheckBox> do not have a property HyperLinkField DataTextField="nombre" NavigateUrl="google.com" HeaderText="direccion"/>. I think something was not being closed and reading the next field as a property.

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.