p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning ASP.NET 1.0 (http://p2p.wrox.com/forumdisplay.php?f=26)
-   -   Editing Datagrid with hyperlink column (http://p2p.wrox.com/showthread.php?t=20312)

shs October 24th, 2004 12:13 AM

Editing Datagrid with hyperlink column
 
Hi
I have a datagrid to edit. when I make one of the columns in the datagrid hyperlinked I can not edit it anymore and I get error msg. here is my code:

'----------------------------------------------------------------
Sub MyGrid_Update(sender As Object, e As DataGridCommandEventArgs)

Dim strCompId as Integer = e.Item.Cells(1).Text
Dim strCompName as String = CType(e.Item.Cells(2).Controls(0), TextBox).Text

Dim strSQL as String = "UPDATE [company] SET [comp_name] = @comp_name where [comp_id] = @comp_id"

.....opening the connection...

 Dim parameterName as OleDbParameter = new OleDbParameter("@comp_name", OleDbType.VarWChar, 50)
        parameterName.Value = strCompName
        myCommand.Parameters.Add(parameterName)
   Dim parameterIdno as OleDbParameter = new OleDbParameter("@comp_id", OleDbType.Integer)
        parameterIdno.Value = strCompId
        myCommand.Parameters.Add(parameterIdno)

        myCommand.ExecuteNonQuery()
        objConn.Close()
        MyGrid.EditItemIndex = -1
        BindData()
End Sub
'----------------------------------------------
here is the grid:
.....
<Columns>
                                <asp:EditCommandColumn EditText=" Edit " ButtonType="PushButton"
    UpdateText="Update" CancelText="Cancel" />


<asp:HyperLinkColumn
HeaderText="ID" DataNavigateUrlField="comp_id"
DataNavigateUrlFormatString="./details.aspx?PositionID={0}"
DataTextField="comp_id"
DataTextFormatString="{0}"
Target="_blank"/>

'---------------------------------------------------
the code works fine when I use
<asp:BoundColumn HeaderText="ID" DataField="comp_id" ReadOnly="true"/>
instead of above hyperlinkcolumn
(I just want to update the company name)
'---------------------------------------------------

<asp:BoundColumn HeaderText="Company Name" DataField="comp_name"
    ItemStyle-HorizontalAlign="Left" />
......
'-------------------------------------------

here is the error:

 Exception Details: System.FormatException: Input string was not in a correct format.

Source Error:

Line 65: Sub MyGrid_Update(sender As Object, e As DataGridCommandEventArgs)
Line 66:
Line 67: Dim strCompId as Integer = e.Item.Cells(1).Text
Line 68: Dim strCompName as String = CType(e.Item.Cells(2).Controls(0), TextBox).Text
Line 69: Dim strCom

'-----------------------------------
Thanks


All times are GMT -4. The time now is 12:22 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.