Hello experts,
Am having issue with my gridview when I right click a page and do refresh. I have just 5 rows in my dataset and when I do a databind the 5 rows is binded to my page once I do a page refresh another 5 rows of same data is binded making it 10 rows on the gridview
control. It continue this way once I refresh. But I noticed this doesn't occur if I use gridview wizard to populate the data using sqldatasource. It happens only if I use code behind dataset.
you can clear your dataset on page postback and rebind it and assign to gridview.
Hello el_abhi
Am really confused as have been on this for a while now. can you help adjust my code below to reflect your profered solution;
If Page.IsPostBack Then
Try
GridView1.DataSource = Nothing
GridView1.DataBind()
Dim selSql As String = "select * from customers where customerid='ALFKI'"
sqlCom.CommandText = selSql
sqlCon.Open()
sqlAdp.Fill(dtS, "T_Customers")
GridView1.DataSource = dtS
GridView1.DataBind()
Catch ex As Exception
MsgBox(ex.Message)
Finally
sqlCon.Close()
End Try
End If
thank you.
Where you declared your dataset dtS? move that declaration part to just above sqlAdp.Fill(dtS,"T_Customers")
Hi,
Where are you declare dtS . please declare it within the module. and do not user shared modifier if you are using.
Hi
are you binding grid in IsPostBack event ?
if (isPostBack()==false){
//Bind grid
}
hi OyBosEnEmm ,
i would suggest you try to use the follow workaround:
If Not Page.IsPostBack Then
Try
GridView1.DataSource = Nothing
GridView1.DataBind()
Dim selSql As String = "select * from customers where customerid='ALFKI'"
sqlCom.CommandText = selSql
sqlCon.Open()
sqlAdp.Fill(dtS, "T_Customers")
GridView1.DataSource = dtS
GridView1.DataBind()
Catch ex As Exception
MsgBox(ex.Message)
Finally
sqlCon.Close()
End Try
End If
i hope it helps you.
沒有留言:
張貼留言