0

I have an aspx page with a table. Each row in the table represents a row of data base table (which represents a place).

I need a way to pass to OnClick event (or another event) a parameter. I can't use the CommandArgument becouse then I will need to know the idPlace string and I just don't know it. I buld the table with FOR loop.

I need something like:

<asp:ImageButton ID="ImageButton1"
                     runat="server" 
                     ImageUrl="Maps.ico"
                     **CommandArgument = '<%=placesDataTable[0]%>'**         
                     />

The main idea that for each place (row) in the table there would be a link to map- a different page which would get the placeId and get the coordinates of the googleMap from another table in data base.

I'm working on it a couple of hours and it's frustrating.

Thanks, Hila

Here is some parts from the code:

<body dir="rtl">

    <form id="form1" runat="server" style="background-color:Fuchsia">

        <!-- Here I will display all the results:-->

        <p style="font-style:italic">Here are the results:</p>

        <table width="100%" border="1" cellpadding="0" cellspacing="0">
    <%
        System.Data.DataTable placesDataTable = (System.Data.DataTable)Session["PlacesDataTable"]; // The table of all the places from the dataBase.
        System.Data.DataRow rowOfPlace;
        for (int i = 0; i < placesDataTable.Rows.Count; i++)
        {             
         <tr>
         <%
             for (int j = 1; j < placesDataTable.Columns.Count; j++)
             {%>
                 <td>
                 <% Response.Write(rowOfPlace[j].ToString()); %>
                 </td>
             <%
             } // end FOR LOOP over the columns 
            // insert MAP column content:
            %>
                 <td>
                     <asp:ImageButton ID="ImageButton1"
                     runat="server" 
                     ImageUrl="Maps.ico"
                     CommandArgument = '<%placesDataTable[i]%>'         
                     />   
                 </td>
         </tr>
         <%
        }
         %>
    </table>

    </form>
</body>

What I want is that when user clicks spesific row (place) I will go to OnClick event IN C# code with the SPECIFIC placeId- and there I'll connect to the data-base, get the coordinates of the place, and Respondr.Rediret to another aspx page- which displays the place on the map. I just need the placeId...

4

1 回答 1

1

您可以使用 Repeater itemcommand 事件来获取命令参数。

 <asp:ImageButton ID="ImageButton1"
                     runat="server" 
                     ImageUrl="Maps.ico"
                     CommandName="MapIt"
                     CommandArgument = '<%#Eval("ID")%>'         
                     />   



protected void rptComments_ItemCommand(object source, RepeaterCommandEventArgs e) {
    if(e.CommandName.ToLower().Equals("mapit")) {
        var id  = int.Parse(((ImageButton)e.CommandSource).CommandArgument);

    }
}

有关更多详细信息,请查看

http://dotnetrush.blogspot.com/2006/12/using-repeater-itemcommand.html

于 2012-04-27T06:22:22.897 回答