Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GridView: Is there a way to display only 100 characters out of 1000 1

Status
Not open for further replies.

leo57

Programmer
Oct 28, 2013
33
0
0
US
The issue is in a WEB page that one field take up the entire page and it makes the grid look ridculus and is unwieldy to work with.
I have a grid view which shows all the records in a SQL table.
It is using a SQLSDatasource So I have tried to put the Select statement to show Left(NominationSummary,100)
this works but if we want to edit it we only see the left 100 not the entire thing. and then when pressing the update button it save the left 100 and drops the rest.
How can I have it only display 100 but yet edit the entire thing and then update the entire thing?
Or can I resize the field and have scroll bars some how?
Code:
SelectCommand="SELECT UniqueID, CommonName, EmployeeEpriseID, Location, VPName, Nominator, 
            ReportToManager, Report1, Report2, Report3, AwardType,  DateAwarded, Event, Awarded, left (NominationSummary,100) as NominationSummary , ePrizeID FROM Recognition
            Where ePrizeID= @ePrizeID
            Order by UniqueID DESC" 
          
            UpdateCommand="UPDATE Recognition SET CommonName = @CommonName, EmployeeEpriseID = @EmployeeEpriseID, 
            Location = @Location, VPName = @VPName, Nominator = @Nominator, ReportToManager = @ReportToManager, 
            Report1 = @Report1, Report2 = @Report2, Report3 = @Report3, AwardType = @AwardType,
             DateAwarded = @DateAwarded, Event = @Event, Awarded = @Awarded, NominationSummary = @NominationSummary, 
             ePrizeID = @ePrizeID WHERE (UniqueID = @UniqueID)">

 
My first suggestion is to NOT use the datasource controls.
Second, to answer your question, you will have to use the RowDataBound event of the gridview.
In there, you will have to get the column data you want and use Substring to take the first 100 chars and display that.

How to do this you might ask. Well, it is easy, however, since you are using a datasource control it may not be.
Code:
'Convert bound dataitem to a DataRowView object.
Dim dataitem As DataRowView = DirectCast(e.Row.DataItem, DataRowView)

.. other code here.. if necessary.

'get the value you need.
Dim partialText As String = dataitem("Your column name here... ")
'Hopefully you are using a template column with a label or some other control in it ...
Dim lblMyTextToDisplay As Label = DirectCast(e.Row.FindControl("lblMyTextToDisplay "), Label)
lblMyTextToDisplay.Text = partialText.SubString((0,100)
 
Well jbenson001 , I ended up doing this. but it took a lot, alotta extra code, adding code manully sort for one
and so on.

 
That's just the way it has to be. You have to write the code. The DataSource controls are not a shortcut for the most part. Most of the time, they cause problems, are not flexible, and not debuggable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top