Results 1 to 7 of 7

Thread: [RESOLVED] how can be added vb code in the html code?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2010
    Posts
    408

    Resolved [RESOLVED] how can be added vb code in the html code?

    my new problem is that i want to add the session.add() command in the datagrid when a hyperlink button of a datagrid is pushed

    i want to store a value(to use it to another page of the site) and i think i have to do that..


    does anyone know how can i put the session add command(or any other vb.net command) in the html hyperlink??

    i thik somehow like this
    <ItemTemplate>
    <asp:HyperLink ID="HyperLink2" runat="server" onclick="<%# %>" NavigateUrl='<%# databinder.eval(container.dataitem,"url") %>' Text='<%# databinder.eval(container.dataitem,"titlos") %>'></asp:HyperLink>

    </ItemTemplate>

    but how exactly??

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: how can be added vb code in the html code?

    Hey,

    The short answer is that you can put code directly in the ASPX markup.

    The slightly longer answer is that you shouldn't. You shouldn't mix server side code with your ASPX markup, put that code where it belongs, on the ServerSide.

    For the sake of clarity, when you talk about a DataGrid, is this actually what you are using, or are you actually using a GridView?

    Gary

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: how can be added vb code in the html code?

    Use a LinkButton instead - it will cause a postback and you'll have to handle the RowCommand/ItemCommand event. You can add the item to session there.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2010
    Posts
    408

    Re: how can be added vb code in the html code?

    with the linkbutton now i must find the number of the row and column that i am

    something like this??

    Protected Sub ela(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)
    Dim id As Integer = e.Item.Cells.GetCellIndex
    Response.Write(ID)
    End Sub

    but how exactly can i find the datagrids row and column in which is the button that has been pushed??
    Last edited by vagelis; Feb 11th, 2010 at 02:44 PM.

  5. #5
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: how can be added vb code in the html code?

    Hey,

    In addition to setting the CommandName of the LinkButton, set the CommandArgument. You can set this on the RowDataBound event, or, as described here:

    http://www.west-wind.com/Weblog/posts/88462.aspx

    Gary

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2010
    Posts
    408

    Re: how can be added vb code in the html code?

    that was a very good suggestion..!!
    it works fine..thank you Gary!!

  7. #7
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] how can be added vb code in the html code?

    Hey,

    Glad to hear that you got it working!!

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width