c# - On ASP.NET ListView with LinqDataSource, display the data when the search button clicked -


If I have a ListView setup with the LinqDataSource and trigger a button search function. To avoid display data on page_load, I click on the list button, bind the search button, and set the result data in the selection of the lunkdays. It works was as I expected, but when it is clicked the search button, then set DataSourceId click on the button it does not look very good I How do I can do a better and clearer way?

ASPX code:

  & lt; asp: LinqDataSource ID = "LinqDataSource1" runat = "server" ContextTypeName = "WebApplication1.DataClasses1DataContext" EntityTypeName = "" TableName = "person to select" = "LinqDataSource1_Selecting" & gt; & Lt; / ASP: LinqDataSource & gt; & Lt; Asp: ListView id = "ListView1" runat = "server" & gt; ... & lt; / Asp: ListView & gt; & Lt; ASP: Button ID = "search" text = "search" runat = "server" click = "search_lized" />  

ASPX.CS code:

  protected void Search_Clicked (object sender, EventArgs e) {ListView1.DataSourceID = LinqDataSource1.ID; ListView1.DataBind (); } Protected void LinqDataSource1_Selecting (object sender, LinqDataSourceSelectEventArgs e) applicable search criteria and the text box {// check here. DataClass1DatatUntext Data = New DataCall 1Datacentax (); Result in data var query =. Results where results. ID & gt; 2 selection results; E. Result = query; }  

I honestly do not see anything wrong in your approach, though, if you Do not like it, an alternate approach just needs to set the code DataSourceID in a static form in its ListView markup, but set Visible = "False" , and after making the click of the button only make it visible.


Comments