Results 1 to 13 of 13

Thread: [ CASE CLOSED ] Uable to delete hyperlink in datagrid. [ CLOSED ]

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    204

    [ CASE CLOSED ] Uable to delete hyperlink in datagrid. [ CLOSED ]

    Hi,
    I've got a datagrid that allows user to select multiple checkboxes and when they click on the button delete on below the datagrid, the items will be deleted. All was going fine till one part where the strDelSoftware keep giving me "" value.

    Coding as below :

    VB Code:
    1. Dim objDb As New SqlClient.SqlConnection
    2.         Dim cmd As New SqlClient.SqlCommand
    3.         Dim objDbReader As SqlClient.SqlDataReader
    4.         Dim i As Integer
    5.         Dim strDelSoftware As String
    6.         Dim strDelServerName As String = Request.QueryString("Server")
    7.  
    8.  
    9.         objDb.ConnectionString = ConfigurationSettings.AppSettings("ConnectionString")
    10.  
    11.         objDb.Open()
    12.         cmd.Connection = objDb
    13.  
    14.         For i = 0 To dgShowServerSoftware.Items.Count - 1
    15.             Dim chk As CheckBox
    16.             chk = dgShowServerSoftware.Items(i).Cells(1).FindControl("chkdel")
    17.             If (chk.Checked = True) Then
    18.  
    19.                 strDelSoftware = CType(dgShowServerSoftware.Items(i).Cells(0).Text, String)
    20.  
    21.                 cmd.CommandText = "Delete ServerSoftwareInstalled where softwareTitle = '" & strDelSoftware & "'and serverName = '" & strDelServerName & "'"
    22.  
    23.                 cmd.ExecuteNonQuery()
    24.             End If
    25.         Next
    26.         objDb.Close()

    Please help

    Regards,
    Roger
    Last edited by Aka Roger; Apr 10th, 2006 at 11:38 PM.
    Appreciated all helps given. Thanks Guys!

  2. #2
    Fanatic Member
    Join Date
    May 2005
    Posts
    608

    Re: Uable to delete hyperlink in datagrid.

    Basically, this part is the one with problems.

    VB Code:
    1. strDelSoftware = CType(dgShowServerSoftware.Items(i).Cells(0).Text, String)

    Put the HTML part of the datagrid to see how you are building it.

    HoraShadow
    I do like the reward system. If you find that my post was useful, rate it.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    204

    Re: Uable to delete hyperlink in datagrid.

    I've done a search in Google and I know it's the hyperlink part. You see, I do not know how can I get the Hyperlink ID when I don't have one.


    <asp:HyperLinkColumn DataNavigateUrlField="softwaretitle" DataNavigateUrlFormatString="SoftwareInfo.aspx?software={0}"
    DataTextField="softwaretitle" HeaderText="Software Installed"></asp:HyperLinkColumn>
    <asp:TemplateColumn HeaderText="X">
    <ItemTemplate>
    <asp:CheckBox id="chkDel" runat="server"></asp:CheckBox>
    </ItemTemplate>
    </asp:TemplateColumn>
    Appreciated all helps given. Thanks Guys!

  4. #4
    Fanatic Member
    Join Date
    May 2005
    Posts
    608

    Re: Uable to delete hyperlink in datagrid.

    You have to add it.

    ID="Lnk"

    So your link would look like this:
    VB Code:
    1. <asp:HyperLinkColumn Id="Lnk" DataNavigateUrlField="softwaretitle" DataNavigateUrlFormatString="SoftwareInfo.aspx?software={0}"
    2. DataTextField="softwaretitle" HeaderText="Software Installed" />

    So on the code behind, you don't 'read' text. You look for the hyperlink, you cast it into an hyperlink and you access the Text property of the Hyperlink.

    Like this:
    [vbcocde]
    strDelSoftware = CType(dgShowServerSoftware.Cells.FindControl("Lnk"), Hyperlink).Text
    [/Highlight]

    This is off my mind, but i'm pretty sure it's accurated.

    HTH
    HoraShadow
    I do like the reward system. If you find that my post was useful, rate it.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    204

    Unhappy Re: Uable to delete hyperlink in datagrid.

    But the hyperlink could not accept the ID. I've got this error when running

    Type 'System.Web.UI.WebControls.HyperLinkColumn' does not have a property named 'Id'.
    Appreciated all helps given. Thanks Guys!

  6. #6
    Fanatic Member
    Join Date
    May 2005
    Posts
    608

    Re: Uable to delete hyperlink in datagrid.

    Ok, I have no VS installed on this computer, because I formated it yesterday.

    I'll get back to you in a few mins
    I do like the reward system. If you find that my post was useful, rate it.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    204

    Re: Uable to delete hyperlink in datagrid.

    Well, if I need to covert the hyperlink control into string, I need the ID do I?
    Correct me if I'm wrong
    Appreciated all helps given. Thanks Guys!

  8. #8
    Fanatic Member
    Join Date
    May 2005
    Posts
    608

    Re: Uable to delete hyperlink in datagrid.

    I edited the last post when I realized about it :P
    I do like the reward system. If you find that my post was useful, rate it.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    204

    Re: Uable to delete hyperlink in datagrid.

    What did you edit??
    Appreciated all helps given. Thanks Guys!

  10. #10
    Fanatic Member
    Join Date
    May 2005
    Posts
    608

    Re: Uable to delete hyperlink in datagrid.

    I've found two ways to solve this:

    Either make it a template column, and inside an <asp:hyperlink> which accepts Id.
    Or
    You can keep the <asp:HyperLinkColumn>, and find the control with the index to cast it into an hyperlink.

    Ex:
    VB Code:
    1. strDelSoftware = CType(dgShowServerSoftware.E.Item.Cells(4).Controls(0), Hyperlink).Text
    You have to put the correct index of cells and the correct index of controls.

    I would go for the first one. Change it to template column and use the Id along with the FindControl method to find the control.

    HTH
    HoraShadow
    I do like the reward system. If you find that my post was useful, rate it.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    204

    Re: Uable to delete hyperlink in datagrid.

    Ok man. I got it. I use using your case 1. Thanks a lot

    PS
    Will up your Rates after I spread some out.
    Appreciated all helps given. Thanks Guys!

  12. #12
    Fanatic Member
    Join Date
    May 2005
    Posts
    608

    Re: Uable to delete hyperlink in datagrid.

    np man

    HoraShadow
    I do like the reward system. If you find that my post was useful, rate it.

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    204

    Re: [ CASE CLOSED ] Uable to delete hyperlink in datagrid. [ CLOSED ]

    If possible. please help me out with this
    Appreciated all helps given. Thanks Guys!

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