GridView SQLDataSource UserControl Problem

G

Guest

I was wondering if someone would be able to help me with the following:

Simply put, I have built an ASP.NET 2.0 WebUserControl (UC1). UC1
contains: A GridView which is bound to an SQLDataSource control (Stored
Procedure with 2 input parameters). The GridView contains 3 columns
(QuestionNumber, QuestionText, and a TemplateField). The TemplateField is
initially empty at design time and is populated with other UserControls which
are dynamically added and bound in the RowDataBound event of the GridView. I
have disabled the ViewState for the GridView as to ensure that the
RowDataBound event is fired every time. What I need to do is pass UC1, 2
parameters which the SQLDataSource will use to execute the stored procedure.
For this, I have added 2 public (Integer type) properties to UC1 so that they
may be specified dynamically.

I then drag-N-drop an instance of my user control (UC1) onto an empty page.
If I set the value of the 2 properties either in the Pre_Init event or the
control properties window in VS 2005, all works well. If I set the
properties in a Buttons’ Click event, nothing works. As I debug, I can see
that the value of the properties are 0. Its as though the assignment of
these properties in the Button’s Click event is fired too late for UC1 to
process them. In UC1, I use the SQLDataSource’s Selecting event to assign
the parameter values
(SqlDataSource1.SelectParameters("LanguageID").DefaultValue = Me.LanguageID),
and use the Init event to execute the SqlDataSource1.Select method. I am
sure I am doing something wrong with my events, etc…. In essence, I need to
pass SQLDataSource parameters to a user control and make it use those
parameters to execute against an SQL stored procedure

P.S.: Also, Is there a way to disable auto selecting/binding of a
form/SQLDataSource, etc… up until I specify .Selec


Regards,

Giovanni
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top