Hello everyone,
My project seems simple. My form populates a datagrid on load (from a database)
I have a search button which works and I can now filter the results.
I also have an onRowCommand which, for now just shows the details of the the selected row.
However, at page load, it seems fine, i can check the details without problem. But, when I do a search. it shows me a different value.
for example.
Hinata [View]
Sakura [View]
Tenten [View]
if search "n"
the result is
Hinata [View]
Tenten [View]
but when i click View of Tenten - It shows SAKURA :(
My Form
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Me.BindGrid("")
End If
End Sub
Hello Again,
I kinda cleaned my code a bit. I also used a viewstate.. but I still get the error.
<pre lang="vb">
Protected Sub lnkSearch_Click(sender As Object, e As EventArgs) Handles lnkSearch.Click
Dim strSearch As String
strSearch = "SELECT Fid,RealName,Department FROM tblUsers" &
" WHERE RealName LIKE '%" & txtName.Text & "%'"
Dim constring As String = "Data Source=LOCALHOST\SQLEXPRESS;Initial Catalog=dbTOD_Sql;Integrated Security=True"
Using con As New SqlConnection(constring)
Using cmd As New SqlCommand(strSearch, con)
cmd.CommandType = CommandType.Text
Using sda As New SqlDataAdapter(cmd)
Using dt As New DataTable()
sda.Fill(dt)
GridView1.AutoGenerateColumns = False
ViewState("vsTable") = dt
Dim dt2 As DataTable = DirectCast(ViewState("vsTable"), DataTable)
GridView1.DataSource = dt2
GridView1.DataBind()
End Using
End Using
End Using
End Using
End Sub
</pre>
Protected Sub GridView1_RowCommand(sender As Object, e As GridViewCommandEventArgs)
Dim rowIndex As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = GridView1.Rows(rowIndex)
'Access Cell values.
Dim customerId As Integer = Integer.Parse(row.Cells(0).Text)
Dim name As String = row.Cells(1).Text
MsgBox (name) 'just for testing
End Sub
What I have tried:
Edited: I tried Viewstate as suggested but I still get the error.
I tried selectedIndexChange but, I still get the same results. I did Computer restarts hoping it was just a bug and a refresh would make the problem go away.
I am lost. I don't know what to do anymore.