hyperlink a field in gridview - ASP.NET

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jagguy
    New Member
    • Sep 2007
    • 23

    hyperlink a field in gridview - ASP.NET

    I have a column on a grid view I read in froma DB. The field has 2 values true or false. Now if i click on the field i want the gridview and the DB updated to the new value. I click on true on a row and it changes it to false after it has reloaded the page just on that row.

    In PHP you just make a field a hyperlink and send data to another page to update and automatically go back and refresh the page .

    In asp.net can i do the saem thing or better?
    q1)how do i make a value clickable and i can get the whole row details from that?
    Last edited by jhardman; Mar 18 '08, 08:03 PM. Reason: moved to .Net forum. ASP forum is for "classic" ASP
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    Hi Jagguy,

    This is a classic ASP forum and as your question relates to ASP.NET you'll receive better advice in the .NET forum.

    In answer to your question, there are a couple of ways to do this but the Grid View provides an easy in-built way to update bound data. Basically you set the AutoGenerateEdi tButton property to true (this generates a column with an edit button) and then define the sql update command to use when the update button is clicked.

    There is an explanation of the various features of a GridView here which has a good example of this.

    This is a simple way which doesn't exactly match your original requirement but I suggest that if you want to go down a different route you try a bit of google or post your question in the .NET forum.

    Hope this helps,

    Dr B

    Comment

    • malav123
      New Member
      • Feb 2008
      • 217

      #3
      Hi,
      You can accomplish your desired task easily by using asp.net, you just have to take link button in your gridview....
      And from the aspx page pass the id or any field and you can use that passed field in gridview and by using that field you can change the gridview row as well as database..
      I think this will helps u....

      Comment

      • jagguy
        New Member
        • Sep 2007
        • 23

        #4
        q1)how do set the commandargument to a row index in the form? i have spent ages on this simple problem.

        I copied this from msdn and it fails .

        Code:
         Protected Sub GridView1_RowCreated1(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
                If e.Row.RowType = DataControlRowType.DataRow Then
        
                     Dim addButton As LinkButton = CType(e.Row.Cells(0).Controls(0), LinkButton)
        'Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.LinkButton'."
                    addButton.CommandArgument = e.Row.RowIndex.ToString()
        
                End If
            End Sub

        Comment

        Working...