=?Utf-8?B?R2VyaGFyZA==?= <(E-Mail Removed)> wrote in
news

E34CC4E-FD84-48F8-B1B9-(E-Mail Removed):
> Thanks.
>
> I'm not quite clear on this, so please be patient.
>
> I have the GridView linked to a DataSource on the page. The
> DataSource has parameters linked to various controls. In the code, I
> assign values to the controls.
>
> In the Load Complete event, if I don't call the GridView data bind,
> the GridView doesn't get populated. If I do call it, it does get
> populated, but the StoredProcedure in the DataSource gets called
> twice.
>
> Seems like the way to go is to do the data bind in the code, but how
> do I set it up so it isn't called in what you call the tagged page
> (this is a term I am afraid I am not familar with, I did a search and
> didn't come up with a definition, just lots of places it was used
> without a definition)? Do I just not associate the GridView with a
> DataSource originally? Please clarify.
>
> I really appreciate your help on this.
Since you have used drag and drop, the bind should be called. I am not
sure, without seeing code, why it is not being called.
One thing to possibly try is using the Page_Load and calling
Page.DataBind() and see if that does a double call to the stored
procedure.
If this does not work, you might be better to move away from the
DataSource control (SqlDataSource, I assume, as this is SQL Server?) and
manually bind.
A manual bind will look like this (with a dataset) - hope C# is your
language of choice:
string connString = ConfigurationManager.ConnectionStrings
["myConnString"].ConnectionString;
string sproc = "{stored proc name here}";
SqlConnection conn = new SqlConnection(connString);
SqlCommand cmd = new SqlCommand(sproc, conn);
cmd.CommandType = CommandType.StoredProcedure;
//if there are parameters
cmd.AddWithValue("@paramName", paramName1);
DataSet ds = new DataSet("{dataset name optional}");
SqlDataAdapter da = new SqlDataAdapter(cmd);
//Can add mappings to friendly name tables, if more than one
da.TableMappings.Add("Table", "{better name here}");
//Note that this try ... finally is equivalent to
//using(SqlConnection conn = new SqlConnection(connString))
//{
//}
try
{
conn.Open();
da.Fill(ds);
}
finally
{
conn.Dispose()
}
MyGridView.DataSource = ds;
MyGridView.DataBind();
The SqlDataSource control encapsulates this type of logic, so it does
the same thing, but it hides it from you.
Peace and Grace,
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
Twitter: @gbworld
Blog:
http://gregorybeamer.spaces.live.com
My vacation and childhood cancer awareness site:
http://www.crazycancertour.com
*******************************************
| Think outside the box! |
*******************************************