getting a specific field from a dataset and displaying it in a label.

S

shelleybobelly

Hi, I am trying to use the ItemCommand in a datagrid (web form) to
display *fields* from the specific row. Each row in the dataset has a
primary key.

The dataset single table is filled from a data adapter and SOME of the
fields are displayed in a datagrid. Everything groovy, no problem.

Now I want the user to click the ReqID (primary key link label) in the
datagrid and display fields FROM THAT ROW ONLY in some labels on the
form. I can't get it to return a field. I am about to give up and go
make another round trip to the database. Which seems silly because I
ALREADY have the data in my dataset. This is all read-only so maybe
could use a late-bound datareader. Not sure.

HELP!

Thanks,

Shelley
 
S

shelleybobelly

I figured it out. I put *everything* (all fields) in the datgrid in
Template Columns. Then I set the Visible property of the hidden columns
to false (has to be done in html, the property pages don't show this
for template columns).

Then I put ID attributes "grxxx" in the html <asp: label> tags inside
the template columns.

Then in my itemCommand, I did this:

try
{
string strItemNumber =
((Label)e.Item.FindControl("grItemNumber")).Text;
string strBuyer = ((Label)e.Item.FindControl("grBuyer")).Text;
string strPO = ((Label)e.Item.FindControl("grPO")).Text;
string strDateDue = ((Label)e.Item.FindControl("grDateDue")).Text;

lblDateDue.Text = strDateDue;
lblPO.Text = strPO;
lblItem.Text = strItemNumber;
lblBuyer.Text = strBuyer;

lblDateDue.Visible = true;
lblPO.Visible = true;
lblItem.Visible = true;
lblBuyer.Visible = true;

}

etc.

It works.
 

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

Top