Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to pass ClientID in OnClientClick
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
OS:
Windows XP
Database:
MS SQL Server
Divers
Thread ID:
01301882
Message ID:
01302650
Vues:
17
It doesn't like this line:


ArrayList list = new ArrayList() { "One", "Two", "Three" };

Do you know how can I fix it?

Thanks in advance.

>I'm not sure what's really being rendered into your HTML instead of the client ID, but at any rate (from reading your other messages), I'm not sure this is the best way to go about this. The object model available on the server side is not the same model available on the client side. So you really don't have access to the rows (and data in the rows) in the same manner. You can do it through Javascript and the DOM (Document Object Model), but honestly that's probably more than you want to get into right now.
>
>Instead, I'd suggest hooking into the data binding events available and injecting the script you want into each row. Here's a sample to at least point you in the right direction:
>
>- Create a new WebForm.
>- Paste this code between the namespace { CODE GOES HERE } braces.
>
>
>public partial class TableRowTest : System.Web.UI.Page
>    {
>        protected void Page_Load(object sender, EventArgs e)
>        {
>            ArrayList list = new ArrayList() { "One", "Two", "Three" };
>
>            this.tblTest.DataSource = list;
>            this.tblTest.DataBind();
>        }
>
>        protected void tblTest_ItemDataBound(object sender, DataGridItemEventArgs e)
>        {
>            if (e.Item.DataItem != null)
>            {
>                HyperLink link = e.Item.FindControl("lnkClick") as HyperLink;
>
>                if (link != null)
>                {
>                    link.Attributes["href"] = "#";
>                    link.Attributes["onclick"] = "return confirm('Navigate to " + e.Item.DataItem.ToString() + "');";
>                }
>            }
>
>        }
>    }
>
>
>In the ASPX page, paste this code after the DOCTYPE section:
>
>
><html xmlns="http://www.w3.org/1999/xhtml" >
><head runat="server">
>    <title>Untitled Page</title>
></head>
><body>
>    <form id="form1" runat="server">
>    <div>
>        <asp:DataGrid runat="server" ID="tblTest" onitemdatabound="tblTest_ItemDataBound">
>            <Columns>
>                <asp:TemplateColumn HeaderText="Test">
>                    <ItemTemplate>
>                        <asp:HyperLink ID="lnkClick" runat="server" Text="< %# Container.DataItem % >"></asp:HyperLink>
>                    </ItemTemplate>
>                </asp:TemplateColumn>
>            </Columns>
>        </asp:DataGrid>
>    </div>
>    </form>
></body>
></html>
>
>
>Run the page. It writes the onclick method for each row as it's bound to the data. Your databinding code will look different since you're probably binding to a DataTable and probably has more than one column (you would usually use the DataBinder.Eval(Container.DataItem, "Column") syntax). I didn't modify the URL it links to, just set it to #, but you can easily do that here - for example, you can have it link to a page and pass in a record value in the querystring.
>
>(please take this as it's intended, just as friendly advice)
>
>Do yourself a favor and pick up a book on ASP.NET if you haven't already - from your questions, you're missing a bit of the fundamentals on how things get hooked together. The nice thing about ASP.NET is that it hides a bunch of complexity from newer developers. The bad thing about ASP.NET is that it hides a bunch of complexity from newer developers, which can lead to an incorrect mental model about what's really happening.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform