2
Reply

Gridview.Datasource is Null

Matin Metanat

Matin Metanat

11 years ago
2.2k

I'm a new & Begginer C# & Asp.net User....

I Have a Gridview in ASP.net that need declare Onblur Function in JS. And for calling Behind Code Method Declare A Hideen Button that call this method . when this Method Call within "Page_Load" Method , the gridview working correctly. But when OnBlur Event Occured and call JS. Function and then call My Behind Code method, datasource dont have any record . (ofcourse there are many record in table)

Please Help me And say where is my Mistake code ?

Thx Alot for answers.

My Code Is :


<script language="javascript" type="text/jscript">  function On_Blur_01(_Content, _ID) {     var e = document.getElementById('<%= mybutton.ClientID %>');     e.click(); }


<asp:Button ID="mybutton" runat="server" OnClick="Show_DataGrid_02" style="display:none;" /> <asp:TextBox ID="Drive_ID" runat="server" Width=253 Height=25 Text="" onblur="On_Blur_01(this.id, 'ID_no');" CssClass="Text_Style_01"></asp:TextBox>


public partial class Main_Transition : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Show_DataGrid_02(this, EventArgs.Empty); .... } ..... }


protected void Show_DataGrid_02(object sender, EventArgs e) { SqlConnection ConnectionString_02 = new SqlConnection(ConfigurationManager.ConnectionStrings["MainConnectionString"].ConnectionString); ConnectionString_02.Open(); SqlCommand mySqlCommand_02 = new SqlCommand("Select * from Ins.Drive", ConnectionString_02); SqlDataReader Dr_02 = mySqlCommand_02.ExecuteReader(); GridView_02.DataSource = Dr_02; // The Datasource is Null And Dont have Data But Dr_02 have Data GridView_02.DataBind(); ConnectionString_02.Close(); }

Answers (2)