Click here to Skip to main content
15,891,951 members
Home / Discussions / ASP.NET
   

ASP.NET

 
Questionretreving images from database problem Pin
developerit30-Apr-10 22:51
developerit30-Apr-10 22:51 
AnswerRe: retreving images from database problem Pin
Abhishek Sur30-Apr-10 23:52
professionalAbhishek Sur30-Apr-10 23:52 
AnswerRe: retreving images from database problem Pin
Abhijit Jana30-Apr-10 23:53
professionalAbhijit Jana30-Apr-10 23:53 
QuestionGRID VIEW Row command Pin
Amit Patel198530-Apr-10 21:24
Amit Patel198530-Apr-10 21:24 
AnswerRe: GRID VIEW Row command Pin
Peace ON30-Apr-10 22:44
Peace ON30-Apr-10 22:44 
QuestionIntegrating Paypal Pin
Gjm30-Apr-10 15:29
Gjm30-Apr-10 15:29 
AnswerRe: Integrating Paypal Pin
Peace ON30-Apr-10 19:45
Peace ON30-Apr-10 19:45 
QuestionBinding Controls via Generic Method Pin
overtech0630-Apr-10 7:17
overtech0630-Apr-10 7:17 
I have a few web applications that I maintain and I find myself very often writing the same block of code over and over again to bind a GridView to a data source. I'm trying to create a Generic method to handle data binding but I'm having trouble getting it to work with Repeaters and DataLists.

Here is the Generic method I have so far:

public void BindControl<T>(T control, SqlCommand sql) where T : System.Web.UI.WebControls.BaseDataBoundControl
{
    cmd = sql;
    cn.Open();
    SqlDataReader dr = cmd.ExecuteReader();
    if (dr.HasRows)
    {
        control.DataSource = dr;
        control.DataBind();
    }
    dr.Close();
    cn.Close();
}


That way I can just define my CommandText then make a call to "BindControls(myGridView, cmd)" instead of retyping this same basic block of code every time I need to bind a grid.

The problem is, this doesn't work with Repeaters or DataLists. The error shown says "There is no implicit reference conversion from 'System.Web.UI.WebControls.Repeater' to 'System.Web.UI.WebControls.BaseDataBoundControl'." I can't seem to find the right base class that is in common with all 3 controls.

For now I have overloaded the method specifically for Repeaters and DataLists, but does anyone know what I could use instead of "BaseDataBoundControl" that would work for all three control types?

- Dave
AnswerRe: Binding Controls via Generic Method Pin
T M Gray30-Apr-10 7:57
T M Gray30-Apr-10 7:57 
GeneralRe: Binding Controls via Generic Method Pin
overtech0630-Apr-10 9:02
overtech0630-Apr-10 9:02 
AnswerRe: Binding Controls via Generic Method Pin
daveyerwin30-Apr-10 11:43
daveyerwin30-Apr-10 11:43 
GeneralRe: Binding Controls via Generic Method Pin
overtech0630-Apr-10 12:01
overtech0630-Apr-10 12:01 
GeneralRe: Binding Controls via Generic Method Pin
daveyerwin30-Apr-10 12:10
daveyerwin30-Apr-10 12:10 
GeneralRe: Binding Controls via Generic Method Pin
daveyerwin30-Apr-10 14:58
daveyerwin30-Apr-10 14:58 
AnswerReturn image from aspx page [modified] Pin
#realJSOP30-Apr-10 3:50
mve#realJSOP30-Apr-10 3:50 
GeneralRe: Return image from aspx page Pin
daveyerwin30-Apr-10 4:40
daveyerwin30-Apr-10 4:40 
GeneralRe: Return image from aspx page Pin
#realJSOP30-Apr-10 4:52
mve#realJSOP30-Apr-10 4:52 
GeneralRe: Return image from aspx page Pin
Abhishek Sur30-Apr-10 6:01
professionalAbhishek Sur30-Apr-10 6:01 
GeneralRe: Return image from aspx page Pin
#realJSOP30-Apr-10 7:38
mve#realJSOP30-Apr-10 7:38 
GeneralRe: Return image from aspx page Pin
Abhishek Sur30-Apr-10 23:45
professionalAbhishek Sur30-Apr-10 23:45 
GeneralRe: Return image from aspx page Pin
#realJSOP1-May-10 0:46
mve#realJSOP1-May-10 0:46 
GeneralRe: Return image from aspx page Pin
Rama Krishna Vavilala30-Apr-10 10:03
Rama Krishna Vavilala30-Apr-10 10:03 
QuestionScreen view fixed to the Last row/item of the Gridview Pin
Sandesh M Patil30-Apr-10 3:49
Sandesh M Patil30-Apr-10 3:49 
AnswerRe: Screen view fixed to the Last row/item of the Gridview Pin
daveyerwin30-Apr-10 7:01
daveyerwin30-Apr-10 7:01 
GeneralRe: Screen view fixed to the Last row/item of the Gridview Pin
daveyerwin30-Apr-10 7:18
daveyerwin30-Apr-10 7:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.