View Single Post
  #1 (permalink)  
Old October 24th, 2004, 12:13 AM
shs shs is offline
Authorized User
 
Join Date: Mar 2004
Location: , , New Zealand.
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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