locked
How to add a object in DataGrid RRS feed

  • Question

  • User-1053303763 posted

    I'm have a probleme with using C#, and i need halp form everyone

     

    when i use a DataGrid, i coud binding the data from dataSet, but i want add some object as Panel or Button or combobox or Label in dataGrid. I have try to seache in MSDN i see that we have collumStyl only CcheckboxCollumStyl so i cannot add a button or combobox in the cell of datagrid. How coud creat the Panel or button or another object in a celle

    Thank

    Friday, September 1, 2006 4:13 AM

All replies

  • User1107770998 posted

    Just add a template column, you can add any control in the template column. Contact me if you have any further questions

     



     

    Friday, September 1, 2006 10:28 AM
  • User-1053303763 posted

    Could you give me a example of this

     

    thank

    Sunday, September 3, 2006 11:26 PM
  • User1107770998 posted
    Following is the example from MSDN
    <%@ Page language="C#" %>

    <html>
      <body>
        <form runat="server">
           
          <h3>TemplateField Example</h3>

          <!-- Populate the Columns collection declaratively. -->
          <!-- Create a custom TemplateField column that uses      -->
          <!-- two Label controls to display an author's first and -->
          <!-- last name in the same column.                       -->
          <asp:gridview id="AuthorsGridView"
            datasourceid="AuthorsSqlDataSource"
            autogeneratecolumns="False"
            runat="server">
                   
            <columns>
                   
              <asp:templatefield headertext="Author Name">
                <itemtemplate>
                  <asp:label id="FirstNameLabel"
                    Text= '<%# Eval("au_fname") %>'
                    runat="server"/>
                  <asp:label id="LastNameLabel"
                    Text= '<%# Eval("au_lname") %>'
                    runat="server"/>
                </itemtemplate>
              </asp:templatefield>
                   
            </columns>
                   
          </asp:gridview>
               
          <!-- This example uses Microsoft SQL Server and connects -->
          <!-- to the Pubs sample database.                        -->
          <asp:sqldatasource id="AuthorsSqlDataSource" 
            selectcommand="SELECT [au_lname], [au_fname], [address], [city], [state], [zip], [contract] FROM [authors]"
            connectionstring="server=localhost;database=pubs;integrated security=SSPI"
            runat="server">
          </asp:sqldatasource>
               
        </form>
      </body>
    </html>
    Monday, September 4, 2006 6:58 AM