views:

49

answers:

2

Hello,

I have this code

<asp:GridView ID="gvCentersList" runat="server" AutoGenerateColumns="False" 
          DataKeyNames="CenterID" DataSourceID="SqlDataSource1" CssClass="gv-classic">
 <Columns>
    <asp:TemplateField HeaderText="">
        <ItemTemplate>
                <asp:CheckBox ID="GridCheckBox" runat="server" onclick="javascript:func1150(this,<%#response.write(CenterID)%>);" />
            </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataField="CenterID" HeaderText="CenterID" SortExpression="CenterID" />
    <asp:BoundField DataField="CenterName" HeaderText="CenterName" SortExpression="CenterName" />                                            
 </Columns></asp:GridView><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnectionString %>" SelectCommand="SELECT ROW_NUMBER() OVER (ORDER BY CityName ASC) AS ROWID, * FROM [CentersList]"></asp:SqlDataSource>

my question in this line

onclick="javascript:func1150(this,<%=CenterID%>);"

how can I pass the CenterID to the func1150 ?

A: 

From my understanding of your question,

onclick=javascript:func1150(this,'<%# Eval("CenterID")%>');

A better way would be adding the onclick attribute from code behind.

Raj Kaimal
Centerid will unfortunately not be the id of the tag. You'd need to go through clientid of the grid to aquire the generated id of the html tag
Rune FS
not working,thanks
Raed
A: 

You may try like this:

<asp:CheckBox 
    ID="GridCheckBox" 
    runat="server" 
    onclick='<%# string.Format("javascript:func1150(this, \"{0}\")", Eval("CenterID")) %>' 
/>

But do you really need a server side checkbox here? If not this could be more readable:

<input 
    type="checkbox" 
    onclick="javascript:func1150(this, '<%# Eval("CenterID") %>');" 
/>
Darin Dimitrov
Fisrt code is correct,Thank you Darin
Raed