.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Databind or not to Databind

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :ASP.Net

i've taken over a project that was originally coded by another developer. for use in the main application, he wrote a custom control in VB. it 'sort of' uses databinding in that he wrote a method called DataBindMe that he calls from both the Load handler of the control and within the application. it's basically a makeshift SpreadSheet control that at some point needs to handle ~2700 records but is very slow in doing so. right now it inherits from both WebControl and the IPostBackEventHandler interface.

because i hate VB, i'm attempting to rewrite the control in C# and at the same time trying to speed the thing up. so this is what i need to know..

will using the built in databinding stuff speed up the control in any way? if so, how do i go about implementing the databinding? there seems to be a few ways to do it. i saw one example that simply overrides both the CreateChildControls and DataBind methods (which seem to do the same thing ??). another has the control inheriting from the DataBoundControl class. yet another has the control inheriting from the IDataItemContainer interface. i mean which is it? how do you know when to use one method over another? and is one method faster than the others?


View Complete Post

More Related Resource Links

ASP.NET repeater control - databind with style

even used the inline editing features, which I at the time thought was the coolest way possible to write ASP.NET code ( I managed to write code to hide all other rows and only show the current one - the row being edited). With a nice looking EditTemplate it looked indeed very slick but it really turned into giant and hard to manage code behind files.

databind from a custom function call


in datalist templatefield, i want to bind an imagebutton's visible property. the scenario is .. it is a picture comments page like one in facebook. if its your own comment, the delete button is shown, otherwise not.  the problem is .. for the imagebutton i want to set visible = false, if the user logged in is the same user as the one who commented. how can i do that ? please help

currently im using this code on datalist databind event. but the label is returned as null

public bool set_visibility()
        Label lb = DataList3.FindControl("Label7") as Label;

        if (lb.Text == Session["user_id"].ToString())
            return true;
            return false;

findcontrol dosent return the control.

Databind ListView datasource and joined tables


Hi all.

I am not expert in ASP so i would be appreciated for the help. Issue connected to Entity FW, ListView Control, its Datasource and type convertion.

I have the  following LINQ query :


RoutesEntities routesModel = new RoutesEntities();
LocalesEntities localesModel = new LocalesEntities();
ObjectQuery routesQuery = (ObjectQuery) from routes in routesModel.Routes
                                                    join locales in localesModel.Locales
                                                    on routes.LocaleID equals locales.LocaleID

When to call DataBind on GridView?

So I have a GridView and several events that can be triggered (such as filtering and inserting a new record) to manipulate the GridView.  I want to make sure that I'm not calling DataBind on Page_Load, especially since I might have to call it again when certain events fire.  Is there a way I can make it so I only have to call DataBind once on the GridView after Page_Load and anything else has fired?  Like some event that will absolutely fire last where I can put my DataBind?  The reason I need to do this is because the DataSource for the GridView is set programmatically from a DataView when the page is loaded, so DataBind needs to run every time.  Just, hopefully, not multiple times each time...

Databind on Gridview throwing System.InvalidCastException. Specific Cast Not Valid

Hello, I am working on a web app where when the user enters data into a text box and presses a filter radio button it should filter the Gridview on the page to the criteria entered.  I have done this before in previous applications with the same code listed below, but for some reason I am now getting the InvalidCastExeption error.  Any help would be appreciated, the source database is SQL and the data field is set to nvarchar and I am using a string to compare as you will see in the code.  I am just unsure why this worked in the past and is not working in this scenario. Thanks, Pete protected void filterLName_CheckedChanged(object sender, EventArgs e) { SHCDataContext existingCustomers = new SHCDataContext(); var filterExistingCustomers = existingCustomers.Customers.Where(c => c.custLastName.Contains(lNameTB.Text.ToString())); displayCustGV.DataSource = null; displayCustGV.DataSourceID = null; displayCustGV.DataSource = filterExistingCustomers; displayCustGV.DataBind(); }   Here is the stack trace....  Specified cast is not valid. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.I

Databind issue, any ideas

I have a stored procedure that returns 3 searches 1) ALL records2) Records staring with something3) Records containing something The stored Proc works fine here is the proc header:CREATE PROCEDURE [dbo].[procGetOHLCSymbolReferenceQuick](@SearchContains VARCHAR(20)='X1234',@SearchStartsWith VARCHAR(20)='X1234') THE ISSUEI have a gridview on a user control, with two texboxes. The gridview is supplied by a SQLDataSource. The textboxes provide that Users Filter demands. The TEXT BOXES <asp:TextBox ID="txtNameStartsWith" runat="server" Width="75px" TextMode="SingleLine"  BackColor="#FFF6CD" /><ajaxtoolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server" TargetControlID="txtNameStartsWith" FilterType="LowercaseLetters,UppercaseLetters,Numbers,Custom"  ValidChars=" @$.^!" /> <asp:TextBox ID="txtNameContains" runat="server" Width="75px" TextMode="SingleLine"  BackColor="#FFF6CD" /><ajaxtoolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender2" runat="server" TargetControlID="txtNameContains" FilterType="LowercaseLetters,UppercaseLetters,Numbers,Custom"  ValidChars=" @$.^!" /> THE SQLPARAMETERS &l

How to databind Frame UriSource from two sources???

I need to create a navigation model where I can load content from listbox menu into frame and at the same time by clicking a usercontrol or a button in the loaded into frame page. I can successfully navigate by clicking menu items. However, I cannot do the same when I initiate page load into frame from already loaded page into frame. I am looking for the right technique to be able to achieve it. Here is what I did so far: I databind UriSource link from xml which is associated with items in the list box this way: Below is the XAML code: <Frame x:Name="ContentFrame" JournalOwnership="OwnsJournal" NavigationUIVisibility="Hidden" HorizontalAlignment="Left" Width="Auto" DataContext="{Binding SelectedItem, ElementName=Nav_ListBox, Mode=OneWay}" Source="{Binding XPath=UriSource}" /> <ListBox x:Name="Nav_ListBox" Margin="0,18,0,0" ScrollViewer.HorizontalScrollBarVisibility="Hidden" Background="#FFF2F2F2" ItemsSource="{Binding Source={StaticResource PagesData}, XPath=page}" /> I created a UserControl to be a container of the loaded data. Then, I generate repetitive content of the loaded page defined in xml. I also define UriSource associated with each item in xml I load into the page. Each item has unique UriSource. <Grid.DataContext> 

Gridview Dropdownlist Databind

Hi All, I am trying to Bind data dropdown list column only inside the gridview  while pageload using asp.net with c#.  I am able to bind the data to it but it is creating rows for total list itmes.  I want to bind to that at the first time i can able to see only one row. Later When i click on any one of the column then it will create a new row. Regards,


if i hv html div element in aspx and i make it runat server i see the div.databind() in intellisense is it of ny significance can anybody elaborate on its use. 

CrystalReportViewer DataBind property - Visual Studio 2010

Hi!  I'm trying to create a Crystal Report to use within a web application.  I have the report created and have added a 'CrystalReportViewer' control to an aspx page.  All the tutorials I've found indicate the next step is "Click on the [...] next to the "Data Binding" Property and bring up the data binding pop-up window".  I'm not seeing a "Data Binding" propert for the 'CrystalReportViewer' control.  The only property I see even related to data binding is "AutoDataBind".Could someone please provide some insight into this?Thanks!!

user control doesn't databind

I reference a user control in my ListView in this manner:<Prf:gradyr ID="GradYrE" runat="server" />This is the user control that's referenced:<asp:Panel ID="pnlGradYr" Visible="true" runat="server"> <div class="label"> <asp:Label ID="lblGradYr" Text="DNHS Grad Year:" runat="server" /> </div> <div class="ctrl"> <asp:TextBox ID="txtGradYr" Text='<%#Bind("GradYr")%>' TabIndex="5" runat="server" /> </div> <div class="req"> <asp:Label ID="lblGradYr_Req" Text="*" ForeColor="#FF0000" runat="server" /> </div> </asp:Panel> The problem is that the #Bind command doesn't update the database, but it does so when I paste the code directly into the aspx page (in other words, without the user control involved). Any suggestions?

Can't edit GridView columns after it's DataBind()


I have a gridview in my web application.  I use a SqlDataAdapter to fill a datatable, and then set my GridView's datasource as the datatable and do a DataBind() on the GridView.  But before I do the datasource selection and the databinding, I try to copy the first column and place it in the second column, and have an autoincrement in the first column ("1", "2", "3", etc.), but it the GridView is just blanked out then.  If I DON'T mess around with those columns then the GridView looks just normal like it should.

What could be going wrong with this???  My method is not working.  Any help is much appreciated.  Thanks in advance. :)

DataBind a toolstriplabel 2.0




I found this code and apply it on my program, but nothing work. I have no error, just nothing appear in the label! I'm using de framework 4.0.

The code I found :

public class BindableToolStripLabel : ToolStripLabel, IBindableComponent {
    #region IBindableComponent Members

    private BindingContext bindingContext;
    private ControlBindingsCollection dataBindings;

    public BindingContext BindingContext {
      get {
        if (bindingContext == null) {
          bindingContext = 

UpdatePanel, GridView and Timer controls used together - OnTick() and DataBind



I am currently working on a page that contains a GridView control which is bound to an ObjectDataSource control.  The ObjectDataSource invokes a method on a DAO layer class that returns a DataTable and all is working just fine.  Paging and Sorting are enabled and work ok as well.  I have "wrapped" the GridView control inside an <UpdatePanel><ContentTemplate> construct and now the Paging and Sorting occur w/o the Page reload as expected - still no problem. 

However, now I want to have the GridView simply refresh itself every 5 to 10 seconds so I placed a Timer control w/ an interval of 5000 milliseconds INSIDE the UpdatePanel.  I am sure there is more that must be wired and have had trouble finding a good article where the UpdatePanel, TimerControl, and GridView control are used together.  Examples that I have seen use Label controls and implement the OnTick event but it is not clear yet to me how to use this w/ a databound control like a GridView.  Can anyone suggest a link or 2 showing an example of this scenario. 

NOTE:  I am not currently programmatically "binding" the GridView control.  The GridView control and ObjectDataSource control are simply bound by setting the DataSourceID property of the GridView to the ID of the ObjectDataSource - they are bou

DataBind a SQLDataSource to a Label


I'm using MikesDotNettings(http://www.mikesdotnetting.com/Article/64/Bind-Data-From-a-SqlDataSource-to-a-Label) code mentioned: Bind Data From a SQLDataSource to a Label, and I'm getting this error:

"An SqlParameter with ParameterName 'ID' is not contained by this SqlParameterCollection."

This is what I have, I'm using my own data to try and populate the labels:


    protected void Page_Load(object sender, EventArgs e)
        DataView dvSql = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
        foreach (DataRowView drvSql in dvSql)
            Label1.Text = drvSql["firstName"].ToString();
            Label2.Text = drvSql["lastName"].ToString();
        //using a OLE DBASE
        //OleDbDataReader rdrSql =
        //               (OleDbDataReader)SqlDataSource2.Select(DataSourceSelectArguments.Empty);
        //while (rdrSql.Read())
        //    Label2.Text = rdrSql["lastName"].ToString();


    protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
        e.Command.Parameters["ID"].Value = 20;

PasswordBox Databind or TextBox mask


Hi all

I know we can´t bind Password property of PasswordBox because security reasons

But how can i Mask a databind TextBox , (llike we do with Windows forms textBox) if don´t needed  this kind of security?


databind a selected gridview row to a couple of formviews


 I have tried several ways but just cannot figure our how to populate some formviews with the data I have brought up in a gridview.

Here is my code so far. I just showing the code behind because my gridview and forms are not a problem. Where I am stuck  is at the GridView1_SelectedIndexChanged at the bottom of the code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class WorkSheetPrint : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
    protected void CheckBoxes(object sender, EventArgs e)
        string str = "SELECT P.CBID, P.CBAddress, P.PAddress, PP.PowerID, PP.EStage, PP.Status, FROM P LEFT JOIN PP ON P.CBID = P.CBID WHERE PP.EStage IN (";
        int flag = 0;
        foreach (ListItem li in CheckBoxList.Items)
            if (li.Selec

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend