problem with Gridview data

D

Durango2008

Hello I have posted on this group and have been helped tremendously, now I
am close to finishing up my work and I am stuck at a single area.
I will explain the situation. Basically I have a Gridview which gets data
from a sqlDataSource tied to the database. The Gridview uses ItemTemplate
to hold LinkButton controls. The Linkbuttons text property is set to
display the data from the database via the sqldatasource. Due to the reason
the data is large I pass it through a function to truncate the data so that
it fits in a reasonable manner on the screen. I do however allow the full
data to be displayed in a textbox at the bottom of the gridview when the
Linkbutton in that particular cell is clicked.
The issue is that it will display the altered data which has been truncated,
and I need to get the original data.
What is a good approach to retrieving the original data again?

Here is some code to better detail it.

<asp:SqlDataSource ID="SqlDataSourceFDIR" runat="server"
ConnectionString="<%$ ConnectionStrings:MyConnString %>"
SelectCommand="Select [ID],[Subject], [Title], [Location], [Misc] FROM
[MyTable] Order By [ID]">
</asp:SqlDataSource>

// LinkButton control within Gridview
<asp:LinkButton ID="lblFdirNum" runat="server" Width="100px" Height="80px"
Forecolor="Black" Font-Underline="false" OnClick="gvCellInfo_OnClick"
ToolTip='<%# convertDispText(Eval("FDIR_Num")) %>'
Text='<%# convertDispText(Eval("FDIR_NUM")) %>'></asp:LinkButton>

protected void gvCellInfo_onClick(object sender, EventArgs e)
{
LinkButton linkBtn = (LinkButton) sender;
cellDataText.Text = linkBtn.Text; <== this displays the truncated data
}

the function convertDispText just takes in the string containing the data
and truncates it and returns it. Unfortunately I rushed and forgot to print
it out, it would be something like this.

protected void convertDispText(object data)
{
return data.toString().SubString(0,20);
}

So I need to figure out how to get the original data that is not truncated
by the convertDispText so that I can display it elsewhere on the page.

Thank you for any help.
 
P

Peter Bromberg [C# MVP]

It's displaying the truncated data because you're using the .Text property
( cellDataText.Text = linkBtn.Text; 0 of the linkButton, which you have
already truncated. The original value in the datasource has not been
truncated, so you need to instead get your data from the correct row and
column of the underlying data source.
Peter
 

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

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top