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

Accessing value from SqlDataSource

P: n/a
I have a SqlDataSource that returns a list of companies and their details by
ProductID from a stored procedure. It also returns the name of the product
associated with the ProductID as the final column (which means it appears
for every record returned). I already have a way of determining how many
rows were returned, and use that information in a label to say "Your search
has returned x records" at the top of the page, above the gridview that
displays the company records:

protected void dsGetSuppliersByProduct_Selected(object sender,
SqlDataSourceStatusEventArgs e)
{
int RecordCount = e.AffectedRows;
if (RecordCount == 0)
{ lblRecordCount.Text = "<p>No Records found</p>"; }
else
{
if (RecordCount == 1)
{ lblRecordCount.Text = "<p>Your search returned 1
record</p>"; }
else
{ lblRecordCount.Text = "<p>Your search returned " + RecordCount
+ " records</p>"; }
}

}

How can I access the ProductName value so that I can extend the label text
to say "Your search has returned x records for <ProductName>" ?

Thanks

Mike
Jan 24 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
You should be able to get the value from the control bound to the
datasource. If you want to get the value from tha dataset, this article may
help you:

http://msmvps.com/blogs/egoldin/arch...atasource.aspx

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Mike" <di*********@microsoft.comwrote in message
news:eS****************@TK2MSFTNGP06.phx.gbl...
>I have a SqlDataSource that returns a list of companies and their details
by ProductID from a stored procedure. It also returns the name of the
product associated with the ProductID as the final column (which means it
appears for every record returned). I already have a way of determining
how many rows were returned, and use that information in a label to say
"Your search has returned x records" at the top of the page, above the
gridview that displays the company records:

protected void dsGetSuppliersByProduct_Selected(object sender,
SqlDataSourceStatusEventArgs e)
{
int RecordCount = e.AffectedRows;
if (RecordCount == 0)
{ lblRecordCount.Text = "<p>No Records found</p>"; }
else
{
if (RecordCount == 1)
{ lblRecordCount.Text = "<p>Your search returned 1
record</p>"; }
else
{ lblRecordCount.Text = "<p>Your search returned " +
RecordCount + " records</p>"; }
}

}

How can I access the ProductName value so that I can extend the label text
to say "Your search has returned x records for <ProductName>" ?

Thanks

Mike


Jan 25 '07 #2

P: n/a
Thanks Eliyahu,

I wasn't binding the value to a control, which is why I couldn't figure out
how to access it. The value was being returned as part of the dataset
because I didn't want to query the database twice if I could help it. It's
a shame my extensive googling didn't turn your article up yesterday. As a
matter of fact, while I was driving home last night, I came up with a very
similar method and applied it successfully this morning:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string pName = DataBinder.Eval(e.Row.DataItem,
"ProductName").ToString();
if (ltProductName.Text == "")
{
ltProductName.Text = " of <strong>" + pName +
"</strong></p>";
}
}
}

ltProductName is a Literal Control, placed after another literal control
which shows the total records based on e.AffectedRows.

Thanks
Mike
"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:e3**************@TK2MSFTNGP05.phx.gbl...
You should be able to get the value from the control bound to the
datasource. If you want to get the value from tha dataset, this article
may help you:

http://msmvps.com/blogs/egoldin/arch...atasource.aspx

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Mike" <di*********@microsoft.comwrote in message
news:eS****************@TK2MSFTNGP06.phx.gbl...
>>I have a SqlDataSource that returns a list of companies and their details
by ProductID from a stored procedure. It also returns the name of the
product associated with the ProductID as the final column (which means it
appears for every record returned). I already have a way of determining
how many rows were returned, and use that information in a label to say
"Your search has returned x records" at the top of the page, above the
gridview that displays the company records:

protected void dsGetSuppliersByProduct_Selected(object sender,
SqlDataSourceStatusEventArgs e)
{
int RecordCount = e.AffectedRows;
if (RecordCount == 0)
{ lblRecordCount.Text = "<p>No Records found</p>"; }
else
{
if (RecordCount == 1)
{ lblRecordCount.Text = "<p>Your search returned 1
record</p>"; }
else
{ lblRecordCount.Text = "<p>Your search returned " +
RecordCount + " records</p>"; }
}

}

How can I access the ProductName value so that I can extend the label
text to say "Your search has returned x records for <ProductName>" ?

Thanks

Mike



Jan 25 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.