ASP.NET - Gridview Column options

Asked By Naresh Kumar
06-Sep-10 05:35 AM
Hi all,

Can I have the gridview in the below format.
HeaderColumn1 HeaderColumn2   HeaderColumn3  
Column Column Column
Column | Column Column | Column Column | Column
Row Row Row Row Row


In this I need to have subColumns in a column , can anyone please let me know how to accomplish this.

Thanks in advance.
  Anand Malli replied to Naresh Kumar
06-Sep-10 05:53 AM
Hi Naresh,

You can surely do it with <asp:template> columns,which provides and allows you to take any control inside gridview,so what you can do is under that column you can create html or asp table which will result in the output which you provided

let me know if anything is there
THANKS
  Naresh Kumar replied to Anand Malli
06-Sep-10 06:09 AM
Thanks for your reply,

Can you please send sample gridview with <asp:Template> columns, that would be better.

  Anand Malli replied to Naresh Kumar
06-Sep-10 06:25 AM
HI Naresh,

i have created one sample grid for you..it does not do anything but just to show you how you can create the layout of your choice by using template column,below is mark up for it

<asp:GridView ID="sampleGrid" runat="server" AutoGenerateColumns="True"
    CellPadding="4" ForeColor="#333333" GridLines="None">
    <RowStyle BackColor="#EFF3FB" />
    <Columns>
      <asp:TemplateField HeaderText="HeaderColumn1">
        <ItemTemplate>
          <label></label>
        </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField HeaderText="HeaderColumn2">
        <ItemTemplate>
          <table border="1" width="100%">
            <tr>
              <td>
                Col1
              </td>
            </tr>
            <tr>
              <td>
                Col2
              </td>
              <td>
                Col3
              </td>
            </tr>
          </table>
        </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField HeaderText="HeaderColumn3">
        <ItemTemplate>
          <table border="1" width="100%">
            <tr>
              <td>
                Col1
              </td>
              <td>
                Col2
              </td>
               
            </tr>
          </table>
        </ItemTemplate>
      </asp:TemplateField>
    </Columns>
    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <EditRowStyle BackColor="#2461BF" />
    <AlternatingRowStyle BackColor="White" />
  </asp:GridView>

now you will write your DataBinder tag inside any of your control where you would like to display the value from db right,but here i am showing how its devided in column and formated..see snapshot


i think this is how you want right...

let me know
thxs
  Naresh Kumar replied to Anand Malli
06-Sep-10 06:58 AM
Thanks a lot for your help.

Have a look at this also,
http://marss.co.ua/MergingGridViewHeaderColumns.aspx



Create New Account
help
data repeaters how do i access this particular column in the repeater row from code behind ? <asp:repeater. . . . < ItemTemplate > < tr > < td > < / td > < td > <% # DataBinder.Eval(Container.DataItem, "SN" )%> . < / td > . . . . . when the values are bound to a label or amy put into the table, i dont understand how to access it. thanks and put Text = ' <% # DataBinder.Eval(Container.DataItem, "SN" )%> ' for the Label's Text Attribute. Since this will be runat t server side anymore. Hi, try the following article and it solves your answer. . . The ASP.NET Repeater is a basic container control that allows you to create custom lists from any data available to the page. It's a handy control, especially since most ASP NET pages that display data need to repeat the same kinds of data over and over of repeater tool would you need? Let's consider the most obvious solution first—the ASP.NET Repeater control. The Repeater control does exactly what its name suggests—it repeats the
when using filters in grid view Hi, I am not able to sort the country column. please let me know how to achieve this. Regards, Amit Agarwal HI refer this example ing The sort ing uses an IComparer derived class, DataGridComparer , that sort s by each column in turn. The code is quite simple. Firstly I cast the object parameters from the public int Compare(DataGridViewCellCollection lhs, DataGridViewCellCollection rhs) { foreach ( Sort ColDefn colDefn in _ sort ed Column s) { int retval = Comparer.Default.Compare( lhs[colDefn.colNum].Value, rhs[colDefn.colNum].Value); if colDefn.ascending ? retval : -retval); } / / These two rows are indistinguishable. return 0 ; } Anonymous delegate When a column is requested by the user to be sort ed, the code needs to determine if that column is already being sort ed. If it is then it is promoted to be the primary sort column (in basic user interface or order swapped if using the Control key). The structure which ColDefn : private struct Sort ColDefn { internal Int16 colNum; internal bool ascending; internal Sort ColDefn( int column Num, Sort Order sort Order) { colNum = Convert.ToInt16( column Num); ascending = ( sort Order ! = Sort Order.Descending); } } The column s that are currently sort ed
photo albam how to create photo albam using asp.net Have a look at the following sample projects: • This article explains an ASP.NET application to view and share photos online. http: / / www.codeproject.com / KB / applications / NetPix.aspx codeproject.com / KB / web-image / EasyThumbs.aspx • How to upload files to Web pages in ASP.NET? How to read an image from a database using ADO.NET and display it in of all of that few best one are these, just help your self http: / / weblogs.asp.net / bleroy / archive / 2005 / 09 / 08 / a-simple-asp-net-photo-album.aspx http: / / www.codedigest
Ajax Slideshow Hi All, I am using the Ajax Slideshow from asp.net / ajax samples. . . . . the sample code is working fine. . . But i want to fetch the images the Data in the Gridview Select FolderName+' \ '+ImageName As Path form Table and give like DataBinder.Eval(Container.DataItem, " Path ") If that Image is inside the Folder than src = . . / <%#DataBinder.Eval(Container.DataItem, " Path ")%> If there are more than Two folder then src = . . / . . / <%#DataBinder.Eval(Container.DataItem, " Path ")%> Just check the Path where is that Image and assign like retrieveDataFromdb) as below. And i assume that you can retireve the entire path in first column (dr[0]) DataSet dataSet = retrieveDataFromdb(); AjaxControlToolkit.Slide[] slide = new AjaxControlToolkit.Slide[dataSet.Tables[0].Rows called Slide’s. These Slide objects are then displayed sequentially on the Slide Show with options to stop, re-play, and choose next and previous images. So if images from the title, title); i++; } } return slides; } Installing the Ajax Control Toolkit Download it from http: / / www.asp.net / ajax / downloads / (for .Net Framework 3.5) Steps: 1. Extract the Ajax Control Toolkit
Datalist: Databinder.Eval and Container.Item I'm using a datalist that displays a business name from a database in a simple manner <%# DataBinder.Eval(Container.DataItem, "BusinessName", "{0}" %> How can I format this 'BusinessName' Before displaying it - specifically be the easiest way) Thanks The first is to use the DataFormatString property in the column itself. In addition, you can use the NullDisplayText field to set a value to be displayed if the data value is null. However, this will only give you limited options on formatting, especially if you're looking at an empty string, which is different than Peters suggestion and it worked - only I had to fill in the details of the Databinder string i.e. <%# evaluate(DataBinder.Eval(Container.DataItem, "VacancyName")) %> and then: protected string evaluate (object check) { if (check = = system.dbnull value) {. . . Sean, I'm using a datalist and still using ASP.Net 1.1 (failed to mention) Thanks! Create New Account