Data Truncation in the gridview (2)

Source: Internet
Author: User

BackgroundCode:

View code

 1   Protected     Void  Page_load (  Object  Sender, eventargs E)
2 {
3 If ( ! Ispostback)
4 {
5 Databind ();
6 }
7
8 }
9 Public Void Databind ()
10 {
11 Sqlconnection con = New Sqlconnection (configurationmanager. connectionstrings [ " Conn " ]. Tostring ());
12 Sqlcommand cmd = New Sqlcommand ();
13 Cmd. Connection = Con;
14 Cmd. commandtext = " Select * from MERs " ;
15 Sqldataadapter da = New Sqldataadapter (CMD );
16 Dataset DS = New Dataset ();
17 Da. Fill (DS );
18 This . Gridview1.datasource = DS. Tables [ 0 ];
19 This . Gridview1.datakeynames = New String [] { " Customerid " };
20 This . Gridview1.databind ();
21 Dataview View = DS. Tables [ 0 ]. Defaultview;
22 For ( Int I = 0 ; I < This . Gridview1.rows. Count; I ++ )
23 {
24 If ( This . Gridview1.pageindex = 0 )
25 {
26 Datarowview rowview = View [I];
27 String Str = Rowview [ " CompanyName " ]. Tostring ();
28 This . Gridview1.rows [I]. cells [ 1 ]. Text = Substringstr (STR, 4 );
29 }
30 Else
31 {
32 Datarowview rowview = View [I + ( This . Gridview1.pageindex * This . Gridview1.pagesize)];
33 String Str = Rowview [ " CompanyName " ]. Tostring ();
34 This . Gridview1.rows [I]. cells [ 1 ]. Text = Substringstr (STR, 4 );
35 }
36
37 }
38 }
39   Public String Substringstr ( String STR, Int Len)
40 {
41 If (Str. Length <= Len)
42 {
43 Return STR;
44 }
45 Else
46 {
47 Return Str. substring ( 0 , Len) + " ... " ;
48 }
49 }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.