Click here to Skip to main content
15,895,283 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
CSS
This Output File:
fileName fileType fileSize filepath createdOn
Asp notes.docx .docx 13539 2013-04-04-05-52\ 4/4/2013 5:52:20 PM
Asp.net.docx .docx 14041 2013-04-04-05-52\ 4/4/2013 5:52:20 PM


I want Display Output like this in GridView1.Combine with fileType and fileSize in same columns in GridView1..


CSS
fileName    fileType&fileSize   filepath     createdOn
Asp notes.docx  .docx 13539  2013-04-04-05-52\   4/4/2013 5:52:20 PM
Asp.net.docx    .docx 14041  2013-04-04-05-52\   4/4/2013 5:52:20 PM


CSS
display in the gridView1
filename,fileType&filesize,filepath,CreatedOn.


Output Like This:

SQL
select fileId,userId,fileName,(fileType + ' ' + fileSize)as fourthcolumn,filepath,createdOn,statusId,lastModifiedOn from fileInfo


In here fileType and FileSize is merge in the fourthColumn..
I want Display in filetype and next line in the fileSize in the same row...

please say
 correct solution Friends!

Advance Thanks Friends!
Posted

Hi,

modify the query like below.
SQL
select fileId,userId,fileName,(fileSize + '<BR>' + fileType)as fileInfo,filepath,createdOn,statusId,lastModifiedOn from fileInfo</br>

and use label in the Item Template of the GridView.

[Edit]

take a template column for a gridview, and in the item template of that template column, add the label like below.
ASP.NET
<asp:Label ID="lblTypeSize" runat="server" Text='<%#Eval("fileInfo")%>' />

where "fileInfo" is a new column gives the concatenated data.

hope it works.
 
Share this answer
 
v3
Comments
Rekhash 8-Apr-13 5:13am    
@Karthik Harve it is not working..
Karthik Harve 8-Apr-13 5:19am    
can you show your gridview html source ? and your code of binding the gridview.
Rekhash 8-Apr-13 5:27am    
@Karthik Harve.
ya sure.. it display value like this filesize<BR>filetype
Can give any ideas about output comes like this
filesize
filetype
Karthik Harve 8-Apr-13 5:45am    
are you using bound field or Template Field (Item Template - label) ? if <BR> is not working then try with "<br/>", but <br/> gives error sometimes when you used ajax.
Rekhash 8-Apr-13 6:02am    
@Karthik Harve. i am bind values in gridview1 in code Behind
use this it is simple to use stored procedure

SQL
Create PROCEDURE usp_getAlldata
(
   @Key varchar(50)
)
AS
BEGIN
select f.fileName,(CONVERT(varchar(50),f.fileType) + '<br>' + CONVERT(varchar(50),f.fileSize)) as fileInfo,f.filepath,f.createdOn,f.statusId,s.statusName from fileInfo As f left join status As s on f.statusId=s.statusId where userId=(select userId from userInfo where email = @Key)
END
GO

</br>

C#
protected void Page_Load(object sender, EventArgs e)
{
    string emailkey = "put your key here";
    DataSet ds = new DataSet();
    SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
    cn.Open();
    SqlCommand cmd = new SqlCommand("usp_getAlldata", cn);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@Key", emailkey);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    da.Fill(ds);
    cmd.ExecuteNonQuery();

    GridView1.DataSource = ds;
    GridView1.DataBind();
}
 
Share this answer
 
v2
You can you template column in gridview and put both the fields in that column.

Please try with the following gridview design fragment:
XML
<asp:TemplateField HeaderText="File Info">
      <ItemTemplate>
           <asp:Label ID="lnkfileType" runat="server" Text='<%# Eval("fileType") %>' ></asp:Label>&nbsp
           <asp:Label ID="lnkfilesize" runat="server" Text='<%# Eval("fileSize") %>' ></asp:Label>&nbsp
      </ItemTemplate>
</asp:TemplateField>
 
Share this answer
 
use this code

SQL
select fileId,userId,fileName,(fileSize + CHAR(10) + fileType)as fourthcolumn,filepath,createdOn,statusId,lastModifiedOn from fileInfo
 
Share this answer
 
v2
Comments
Rekhash 8-Apr-13 6:05am    
@PRAKASH9 it is not working,..
Rekhash 8-Apr-13 6:22am    
@PRAKASH9 will U suggest another answer...
PRAKASH9 8-Apr-13 7:00am    
@Rekhash check my solution
use this solution

SQL
Create PROCEDURE usp_getAlldata
AS
BEGIN
select fileId,userId,fileName,(CONVERT(varchar(50),fileSize ) + '<br>' + CONVERT(varchar(50),fileType)) as fourthcolumn,filepath,createdOn,statusId,lastModifiedOn from fileInfo
END
GO
</br>



ASP.NET
<asp:gridview id="GridView1" runat="server" autogeneratecolumns="false">
       <columns>
       <asp:boundfield datafield="fileId" htmlencode="false" />
       <asp:boundfield datafield="userId" htmlencode="false" />
       <asp:boundfield datafield="fileName" htmlencode="false" />
       <asp:boundfield datafield="fourthcolumn" htmlencode="false" />
       </columns>
       </asp:gridview>




C#
protected void Page_Load(object sender, EventArgs e)
   {
       DataSet ds = new DataSet();
       SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
       cn.Open();
       SqlCommand cmd = new SqlCommand("usp_getAlldata", cn);
       cmd.CommandType = CommandType.StoredProcedure;
       SqlDataAdapter da = new SqlDataAdapter(cmd);
       da.Fill(ds);
       cmd.ExecuteNonQuery();

       GridView1.DataSource = ds;
       GridView1.DataBind();
   }
 
Share this answer
 
v2
Comments
Rekhash 8-Apr-13 23:39pm    
@PRAKASH9
string query = "select f.fileName,(f.fileType + '' + f.fileSize)as fileInfo,f.filepath,f.createdOn,f.statusId,s.statusName from fileInfo As f left join status As s on f.statusId=s.statusId where userId=(select userId from userInfo where email ='" + key + "')";

how to write in stored proc and filetype and filesize merge into one one column. in same column it will display like this
filetype
filesize
PRAKASH9 9-Apr-13 1:59am    
see my updated solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900