GridView issue

R

ram_kri

Hi Guys,
Here is a uncommon scenario that I had to work on..

I have a GridView which is associated to a DataSource. But I have a couple
of columns (item-templates while the rest of the columns are
boundfields)which have labels. Now, the datasouce that is bound to the
GridView doesnt provide values to the itemTemplate columns. So in the
page_load event I manually obtain the data from the DB and then process
it, loop through the rows of the GridView to find the specific label that
I want in the specific cell and then set the text to the found lable
control based on the DataKey value of the row.

Everything works fine.

But the GridView has the 'ShowEditButton" set to "true". So one gets to
see "Edit" as the first column. Now when clicked on that, my itemTemplate
columns are not being populated.

I debugged the issue and I can see that the label population logic is
being executed and data is also coming properly, but after executing that
code, control jumps into the aspx code near to the "ItemTempalte" tag and
after that the execution completes and finally when I see the page, the
ItemTemplate column values are Not Populated at all. Its EMPTY.
Note : As I am binding the data for the ItemTemplate (Lable) columns in
the the codebehind that, for the asp:label tags inside the itemTemplates I
didnt specify the "Text='abc'" attribute at all. Means its totally missing
in the asp:Label tag.

What's going on here...Any help on this would be really helpful.

One solution that I can think of is, in the aspx itself for the
itemTemplate Label columns I can set the "Text=<%#
GetDataForThisLabel(dataKeyValue) %>

But now, how do I get the dataKeyValue in the aspx page ? If the row is
selected then I can somehow get the dataKey for the row, but here in aspx
how do I specify that the parameter to the GetDataForThisLabel would be
the DataKeyValue of that row ?

Any ideas ???

Have a nice day.

Regards,
kris
 
R

ram_kri

Hi Guys,
I got the issue resolved by adding the population of ItemTemplate Labels
in the GridView's "OnDataBound" event.

Things look ok now.

But still if anybody knows how to get it solved using the solution that I
proposed, it would be great.
Thank you in advance.

Regards,
kris
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top