Problem with String Data Type

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm working with a DataGrid UpdateCommand event and running into a problem.
The second column of the dg is the PK named "FlitchNum". The datatype of
this PK is varchar(string). In the event I need to obtain the value of this
field in order to pass it into a SQL command. However, when I use the
syntax: "Dim FlitchID As String = e.Item.Cells(1).Text" nothing populates the
FlitchID variable. Below is the code. How do I simply select the textual
value of the contents of column 3? Thanks
-------------------------------------------------------------------------------------
Private Sub DataGrid1_UpdateCommand(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) _
Handles DataGrid1.UpdateCommand
Dim DDL As DropDownList = _
CType(e.Item.Cells(2).Controls(1), DropDownList)
Dim NewShip As Integer = DDL.SelectedValue
Dim FlitchID As String = e.Item.Cells(1).Text
Response.Write(FlitchID)
Dim SQL As String = _
"UPDATE tblLogs SET SpecieID=@Specie WHERE FlitchID=@ID"
Dim Conn As SqlConnection = New SqlConnection("integrated
security=SSPI;data source=sjserver1;persist security info=False;initial
catalog=sjerp")
Dim Cmd As New SqlCommand(SQL, Conn)
Cmd.Parameters.Add(New SqlParameter("@Specie", NewShip))
Cmd.Parameters.Add(New SqlParameter("@ID", FlitchID))
Conn.Open()
Cmd.ExecuteNonQuery()
Conn.Close()
DataGrid1.EditItemIndex = -1
DataGrid1.DataBind(
-------------------------------------------------------------------------------------
 
MrMike said:
I'm working with a DataGrid UpdateCommand event and running into a problem.
The second column of the dg is the PK named "FlitchNum". The datatype of
this PK is varchar(string). In the event I need to obtain the value of this
field in order to pass it into a SQL command. However, when I use the
syntax: "Dim FlitchID As String = e.Item.Cells(1).Text" nothing populates the
FlitchID variable.

That sounds very strange. Does e.Item.Cells(1).Text definitely have a
non-null value? How are you determining that FlitchID has not been set?
 
Thanks for your reply. FlitchNum is the PK, so it cannot contain a null
value. This column is a template column, generated using the code below.
Should this make any difference? Thanks.

<asp:TemplateColumn HeaderText="Flitch#">
<ItemTemplate>
<asp:HyperLink runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.FlitchNum") %> ' NavigateURL='<%# "Logs_Detail.aspx?id=" &
DataBinder.Eval(Container, "DataItem.FlitchNum") %>' Target="_self"
Name="HyperLink1">
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
 
MrMike said:
Thanks for your reply. FlitchNum is the PK, so it cannot contain a null
value.

That may be true in theory, but is it true in your particular case? It
seems more likely that that would be wrong than that variable
assignment is broken.
This column is a template column, generated using the code below.
Should this make any difference? Thanks.

Don't know, I'm afraid...
 
Your FlitchNum is stored in the HyperLink's Text attribute, not in the Text
attribute of the DataGrid's Cell.

You need to give your HyperLink an ID and use e.FindControl("<ID>") to get
an instance of your control and cast it to the type of HyperLink. Then you
can extract the FlitchNum from the control's Text property.
 
Back
Top