This is a migrated thread and some comments may be shown as answers.

[Solved] Advanced Databinding produces duplicate columns

3 Answers 297 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Drew
Top achievements
Rank 2
Drew asked on 13 Jan 2010, 09:39 PM


Ok I need a solution to a problem I keep running into. Basically, I want the edit and delete command columns to be the rightmost columns on my grid. However, when I use the advanced databinding technique, the edit and delete command options are in the leftmost columns.

I tried explicitly declaring my data columns in the <column> section of the masterTableView, but the only thing that does is cause the needDataSource event to duplicate the collumns.

Here is my grid declairation markup:

<telerik:RadGrid ID="gvFirmInfo" runat="server" Width="550px"
    <MasterTableView  
        EditMode="PopUp"  
        CommandItemDisplay="Bottom" CommandItemStyle-BackColor = "#D8D8D8" 
        ShowHeader="true" ShowHeadersWhenNoRecords="false" NoMasterRecordsText="" 
        HeaderStyle-Font-Bold="true" HeaderStyle-BackColor ="#D8D8D8" 
        ItemStyle-BackColor="White" ItemStyle-BorderColor="#C9C4D1"  
        ItemStyle-BorderStyle="Solid" ItemStyle-BorderWidth="1px"  
        AlternatingItemStyle-BackColor="#E0E0E0" AlternatingItemStyle-BorderStyle="Solid" 
        AlternatingItemStyle-BorderWidth="0px" AlternatingItemStyle-BorderColor="#FFFFFF" 
        BorderColor="#C9C4D1" BorderWidth="1px" BorderStyle="Solid" 
        GridLines="None"
         
        <CommandItemTemplate>  
            <div style="text-align: right; padding: 8px;"
                <asp:Button ID="Button1" Text="Add Firm Location"  
                Runat="server" CommandName="InitInsert"></asp:Button>  
            </div> 
        </CommandItemTemplate>  
         
        <Columns> 
            <telerik:GridBoundColumn DataField="city" HeaderText="City"
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="Country" HeaderText="Country"
            </telerik:GridBoundColumn> 
             
            <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="columnDelete" 
                ConfirmText="Are you sure you want to delete this record?"
            </telerik:GridButtonColumn> 
            <telerik:GridEditCommandColumn UniqueName="EditCommandColumn"
            </telerik:GridEditCommandColumn> 
        </Columns> 
         
        <EditFormSettings> 
         <!-- I have a custom edit form in here --> 
        </EditFormSettings> 
         
    </MasterTableView> 
 
    <ClientSettings> 
        <ClientEvents OnPopUpShowing="PopUpShowing" /> 
    </ClientSettings> 
</telerik:RadGrid> 


Here is my VB:

    Protected Sub gvFirmInfo_NeedDataSource(ByVal source As ObjectByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles gvFirmInfo.NeedDataSource 
        Dim sqlString As String = "" 
        Dim sqlparam(2) As SqlParameter 
        Dim ds As New DataSet 
        Dim dr As SqlDataReader = Nothing 
 
        Try 
            SetParam(sqlparam(0), "@recId", Data.SqlDbType.Int, 4, m_rec_id) 
            SetParam(sqlparam(1), "@recType", Data.SqlDbType.Char, 2, m_rec_type) 
 
 
            
                sqlString = "SELECT ... FROM..."  
 
            ds = SqlHelper.ExecuteDataset(Conn, Data.CommandType.Text, sqlString, sqlparam) 
 
 
            gvFirmInfo.DataSource = ds
 
 
        Catch ex As Exception 
 
        End Try 
 
    End Sub 


Most likely I have been ripping my hair out over something stupid.... any suggestions?



3 Answers, 1 is accepted

Sort by
0
Drew
Top achievements
Rank 2
answered on 14 Jan 2010, 07:12 PM
Is there a way to pre-determine where the columns should be and set their attributes while using advanced databinding?

That is ultimately what I am trying to accomplish here
0
Drew
Top achievements
Rank 2
answered on 14 Jan 2010, 07:46 PM
*Bump*

I was able to get my grid to show up the way I wanted it to, but the only way I could get a desired result was to hide any columns as they are generated.

This can't be the correct way to do this...

Protected Sub gvFirmInfo_ColumnCreated(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridColumnCreatedEventArgs) Handles gvFirmInfo.ColumnCreated  
        Try 
            If e.Column.HeaderText.ToLower = "city" Then 
                CType(e.Column, GridBoundColumn).Display = False 
            End If 
            If e.Column.HeaderText.ToLower = "country" Then 
                CType(e.Column, GridBoundColumn).Display = False 
            End If 
 
        Catch ex As Exception  
        End Try 
    End Sub 
0
Drew
Top achievements
Rank 2
answered on 14 Jan 2010, 09:09 PM
Answer =    
AutoGenerateColumns="false"
Tags
Grid
Asked by
Drew
Top achievements
Rank 2
Answers by
Drew
Top achievements
Rank 2
Share this question
or