This is of course in VB.net for my script except for some Javascript, but hoping this is clearer... I tried rebinding the gridview but that doesn't work in part as this is much more complex than I thought it to be.
I have a popup that populates the gridview based on choosing a line from a gridview on the THAT popup... so then the textbox is successfully populated but it does not refresh the gridview on the base page:
'BASE PAGE
Protected Sub btnFindPO_Click(sender As Object, e As System.EventArgs)
If Not IsPostBack Then
Me.btnFindPO.Attributes.Add("onclick", "javascript:return OpenPopup()")
End If
End Sub
Protected Sub txtLastName_TextChanged(sender As Object, e As System.EventArgs)
Me.Gridview1.DataBind()
End Sub
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles Gridview1.RowDataBound
If (e.Row.RowType = DataControlRowType.DataRow) Then
'assuming that the required value column is the second column in gridview
DirectCast(e.Row.FindControl("btnSelect"), Button).Attributes.Add("onclick", "javascript:GetRowValue('" & e.Row.Cells(1).Text & "','" & e.Row.Cells(2).Text & "','" & e.Row.Cells(3).Text & "','" & e.Row.Cells(4).Text & "','" & e.Row.Cells(5).Text
& "','" & e.Row.Cells(6).Text & "')")
End If
End Sub
I have a popup that populates the gridview based on choosing a line from a gridview on the THAT popup... so then the textbox is successfully populated but it does not refresh the gridview on the base page:
Make sure update the gridview data source first and immediately rebind the gridview.
Please mark the replies as answers if they help or unmark if not.
Feedback to us
Eugene1968
Member
90 Points
360 Posts
refresh gridview
Nov 23, 2012 03:53 PM|LINK
I have a gridview and a textbox on my form... how can I get my gridview to refresh when a value is changed in the textbox?
chandan777
Member
190 Points
261 Posts
Re: refresh gridview
Nov 23, 2012 03:57 PM|LINK
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
// Your function to bind gridview
BindGridView();
}
MahadTECH
Star
8978 Points
1660 Posts
Re: refresh gridview
Nov 23, 2012 04:34 PM|LINK
Chandan is right.
TextBox.TextChanged Event
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox.textchanged.aspx
protected void TextBox1_TextChanged(object sender, EventArgs e) { GridView1.DataBind(); }Good Luck`
Mahad Bin Mukhtar
Remember to Mark the replies as Answers
The easiest day was 'yesterday'.
MCP, MCSD
For .NET TECH Blog
Eugene1968
Member
90 Points
360 Posts
Re: refresh gridview
Nov 23, 2012 05:11 PM|LINK
This is of course in VB.net for my script except for some Javascript, but hoping this is clearer... I tried rebinding the gridview but that doesn't work in part as this is much more complex than I thought it to be.
I have a popup that populates the gridview based on choosing a line from a gridview on the THAT popup... so then the textbox is successfully populated but it does not refresh the gridview on the base page:
'BASE PAGE
Protected Sub btnFindPO_Click(sender As Object, e As System.EventArgs)
If Not IsPostBack Then
Me.btnFindPO.Attributes.Add("onclick", "javascript:return OpenPopup()")
End If
End Sub
Protected Sub txtLastName_TextChanged(sender As Object, e As System.EventArgs)
Me.Gridview1.DataBind()
End Sub
</script>
<script type="text/javascript">
function OpenPopup() {
window.open("ViewPOs1.aspx", "List", "scrollbars=yes,resizable=no,width=700,height=600");
return false;
}
</script>
'POPUP
<script language="javascript">
function GetRowValue(val1) {
window.opener.document.getElementById("txtLastName").value = val1;
window.close();
}
</script>
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles Gridview1.RowDataBound
If (e.Row.RowType = DataControlRowType.DataRow) Then
'assuming that the required value column is the second column in gridview
DirectCast(e.Row.FindControl("btnSelect"), Button).Attributes.Add("onclick", "javascript:GetRowValue('" & e.Row.Cells(1).Text & "','" & e.Row.Cells(2).Text & "','" & e.Row.Cells(3).Text & "','" & e.Row.Cells(4).Text & "','" & e.Row.Cells(5).Text & "','" & e.Row.Cells(6).Text & "')")
End If
End Sub
chaaraan
Contributor
2170 Points
484 Posts
Re: refresh gridview
Nov 24, 2012 01:37 AM|LINK
Hi,
Add the Datasource property before binding the GridView
Protected Sub txtLastName_TextChanged(sender As Object, e As System.EventArgs)
Me.Gridview1.DataSource = "sometable"
Me.Gridview1.DataBind()
End Sub
Regards,
Charan
oned_gk
All-Star
36112 Points
7370 Posts
Re: refresh gridview
Nov 24, 2012 03:56 PM|LINK
Suwandi - Non Graduate Programmer
sarathi125
Star
13599 Points
2691 Posts
Re: refresh gridview
Nov 25, 2012 06:11 AM|LINK
Hi,
Check this link,
http://www.c-sharpcorner.com/blogs/7620/search-into-textbox-and-bind-gridview-using-asp-net.aspx
Remember to click Mark as Answer on the post that helps to others.
My Blog :MyAspSnippets
Frank Jiang ...
All-Star
16006 Points
1728 Posts
Microsoft
Re: refresh gridview
Nov 27, 2012 07:33 AM|LINK
Make sure update the gridview data source first and immediately rebind the gridview.
Feedback to us
Develop and promote your apps in Windows Store