By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,742 Members | 793 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,742 IT Pros & Developers. It's quick & easy.

GridView SQLDataSource UserControl Problem

P: n/a
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").Def aultValue = 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

May 10 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.