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

Binding ascx controls doesnt work

2 Answers 176 Views
Grid
This is a migrated thread and some comments may be shown as answers.
DragonBall
Top achievements
Rank 1
DragonBall asked on 22 Aug 2008, 08:54 AM

I have problems binding my ascx file to control, during debug time you can see the data being inserted to the controls that is inside the ascx file but when the process is finish it doesnt return anything, it doesnt bind.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Ticket_Default" %>
<%@ Reference Control="~/Component/DAL/Tickets.ascx" %>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
<telerik:RadScriptManager ID="RadScriptManager1" Runat="server">
</telerik:RadScriptManager>


<telerik:RadGrid ID="RadGridTicket" runat="server" AutoGenerateColumns="false"
onneeddatasource="RadGridTicket_NeedDataSource"

PageSize="5" OnItemUpdated="RadGridTicket_ItemUpdated"
OnItemInserted="RadGridTicket_ItemInserted"
OnUpdateCommand="RadGridTicket_UpdateCommand"
onitemcommand="RadGridTicket_ItemCommand" >
<MasterTableView AllowPaging="True" EditMode="PopUp" CommandItemDisplay="Top">
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton"
UpdateImageUrl="/Update.gif" >
</telerik:GridEditCommandColumn>
<telerik:GridButtonColumn CommandName="Delete" Text="Delete"
UniqueName="Delete" >
</telerik:GridButtonColumn>
<telerik:GridBoundColumn
UniqueName="ParentTicketId"
HeaderText="Parent Ticket Id"
DataField="ParentTicketId"
ReadOnly="true"
Display="false">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn
UniqueName="Title"
HeaderText="Title"
DataField="Title"
EditFormColumnIndex="3">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn
UniqueName="Details"
HeaderText="Details"
DataField="Details">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn
UniqueName="IsHtml"
HeaderText="Is Html"
DataField="IsHtml">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn
UniqueName="Owner"
HeaderText="Owner"
DataField="Owner">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn
UniqueName="UserIdAssignedTo"
HeaderText="UserId Assigned To"
DataField="UserIdAssignedTo"
ReadOnly="true"
Display="false">
</telerik:GridBoundColumn>

<telerik:GridBoundColumn
UniqueName="CurrentStatusSetBy"
HeaderText="Current Status Set By"
DataField="CurrentStatusSetBy">
</telerik:GridBoundColumn>


<telerik:GridBoundColumn
UniqueName="PriorityId"
HeaderText="Priority Id"
DataField="PriorityId"
ReadOnly="true"
Display="false">
</telerik:GridBoundColumn>

<telerik:GridBoundColumn
UniqueName="AffectsCustomer"
HeaderText="Affects Customer"
DataField="AffectsCustomer">
</telerik:GridBoundColumn>

<telerik:GridBoundColumn
UniqueName="PublishedToKb"
HeaderText="Published To Kb"
DataField="PublishedToKb">
</telerik:GridBoundColumn>

<telerik:GridBoundColumn
UniqueName="CompanyId"
HeaderText="Company Id"
DataField="CompanyId"
readonly="true"
display="false">
</telerik:GridBoundColumn>

<telerik:GridBoundColumn
UniqueName="PercentageCompleted"
HeaderText="Percentage Completed"
DataField="PercentageCompleted">
</telerik:GridBoundColumn>

<telerik:GridBoundColumn
UniqueName="Active"
HeaderText="Active"
DataField="Active">
</telerik:GridBoundColumn>

<telerik:GridBoundColumn
UniqueName="TicketCreatedByUserId"
HeaderText="TicketCreated By UserId"
DataField="TicketCreatedByUserId">
</telerik:GridBoundColumn>

<telerik:GridBoundColumn
UniqueName="ProjectId"
HeaderText="Project Id"
DataField="ProjectId"
ReadOnly="true"
Display="false">
</telerik:GridBoundColumn>

<telerik:GridBoundColumn
UniqueName="ProjectGroupId"
HeaderText="Project Group Id"
DataField="ProjectGroupId"
ReadOnly="true"
Display="false">

</telerik:GridBoundColumn>

<telerik:GridBoundColumn
UniqueName="StartDate"
HeaderText="Start Date"
DataField="StartDatee">
</telerik:GridBoundColumn>

<telerik:GridBoundColumn
UniqueName="EndDate"
HeaderText="End Date"
DataField="EndDate">
</telerik:GridBoundColumn>
</Columns>
<RowIndicatorColumn Visible="False" >
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>

<ExpandCollapseColumn Visible="False" Resizable="False">
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>

<EditFormSettings EditFormType="WebUserControl"
ColumnNumber="3" UserControlName="~\Component\DAL\Tickets.ascx" PopUpSettings-Width="800px">
<EditColumn UniqueName="EditCommandColumn1"></EditColumn>

<PopUpSettings ScrollBars="None"></PopUpSettings>
</EditFormSettings>
</MasterTableView>
</telerik:RadGrid>
</form>
</body>
</html>


Ticket.ascx.cs

using System;  
using System.Collections;  
using System.Configuration;  
using System.Data;  
using System.Linq;  
using System.Web;  
using System.Web.Security;  
using System.Web.UI;  
using System.Web.UI.HtmlControls;  
using System.Web.UI.WebControls;  
using System.Web.UI.WebControls.WebParts;  
using System.Xml.Linq;  
using System.Data.SqlClient;  
using Telerik.Web.UI;  
using MWS2;  
using MWS2.CollectionClasses;  
using MWS2.EntityClasses;  
 
public partial class Component_DAL_Tickets : System.Web.UI.UserControl  
{  
    private int _TicketID;  
    public int TicketID  
    {  
 
        get { return _TicketID; }  
        set { _TicketID = value;  
        _TicketEntity = new MwsTicketsEntity(_TicketID);  
        bindFormTicketControlFormObject();  
        }  
    }  
    private String _editMode;  
    public string EditMode  
    {  
 
        get { return _editMode; }  
        set  
        {  
            _editMode = value;   
        }  
    }  
    private MwsTicketsEntity _TicketEntity;  
    public MwsTicketsEntity TicketEntity  
    {  
 
        get { return _TicketEntity; }  
        set { _TicketEntity = value; }  
    }  
 
 
    protected void Page_PreRender(object sender, EventArgs e)  
    {  
 
   // bindFormTicketControlFormObject();  
    }  
 
 
    protected void Page_Load(object sender, EventArgs e)  
    {  
 
        if (!IsPostBack)  
        {  
 
              
                   
        }  
 
          
         if (!string.IsNullOrEmpty(_editMode) || (_TicketEntity != null))  
        {  
               
            if (_editMode == "Edit")  
            {  
                  
            }  
            else  
            {  
 
 
            }//presume it is an insert  
        }  
        else  
        {  
              
              
 
        }  
 
         
 
    }  
 
 
    private void bindFormTicketControlFormObject() {  
 
        //_TicketEntity = new MwsTicketsEntity(33);  
        ParentTicketIdText.Text = Convert.ToString(TicketEntity.MwsTickets.ParentTicketId);  
        ParentTicketIdText.DataBind();  
        PriorityIdText.Text = Convert.ToString(TicketEntity.MwsTickets.PriorityId);  
        TicketCreatedByUserIDText.Text = Convert.ToString(TicketEntity.MwsTickets.TicketCreatedByUserId);  
        TitleText.Text = TicketEntity.MwsTickets.Title;  
        AffectsCustomerCheckBox.Checked = TicketEntity.MwsTickets.AffectsCustomer;  
        ProjectIdText.Text = Convert.ToString(TicketEntity.MwsTickets.ProjectId);  
        IsHtmlCheckBox.Checked = TicketEntity.MwsTickets.IsHtml;  
        PublishedToKbCheckBox.Checked = TicketEntity.MwsTickets.PublishedToKb;  
        ProjectGroupIdText.Text = Convert.ToString(TicketEntity.MwsTickets.ProjectGroupId);  
        OwnerText.Text = TicketEntity.MwsTickets.Owner;  
        CompanyIdText.Text = Convert.ToString(TicketEntity.MwsTickets.CompanyId);  
        StartDateText.Text = Convert.ToString(TicketEntity.MwsTickets.StartDate);  
        UserAssignToText.Text = Convert.ToString(TicketEntity.MwsTickets.UserIdAssignedTo);  
        PercentageCompleteText.Text = Convert.ToString(TicketEntity.MwsTickets.PercentageCompleted);  
        EndDateText.Text = Convert.ToString(TicketEntity.MwsTickets.EndDate);  
        CurrentStatusSetByText.Text = TicketEntity.MwsTickets.CurrentStatus;  
        ActiveText.Checked = TicketEntity.MwsTickets.Active;  
        DetailText.Text = TicketEntity.MwsTickets.Details;  
        CurrentStatusText.Text = TicketEntity.MwsTickets.CurrentStatus;  
            
        
    }  
 
 
    protected void btnUpdate_Click(object sender, EventArgs e)  
    {  
          
        int ParentTicketId=Convert.ToInt32(ParentTicketIdText.Text);  
        int UserAssignTo=Convert.ToInt32(UserAssignToText.Text);  
        int PriorityId=Convert.ToInt32(PriorityIdText.Text);  
        int CompanyIdConvert.ToInt32(CompanyIdText.Text);  
        int PercentageCompleted = Convert.ToInt32(PercentageCompleteText.Text);  
        int TicketCreatedByUserID = Convert.ToInt32(TicketCreatedByUserIDText.Text);  
        int projectIdConvert.ToInt32(ProjectIdText.Text);  
        int ProjectGroupId=Convert.ToInt32(ProjectGroupIdText.Text);  
        DateTime startdate = Convert.ToDateTime(StartDateText.Text);  
            DateTime endDate = Convert.ToDateTime(EndDateText.Text);  
            DAL.Lite.Ticket.TicketsUpdate(33,ParentTicketId, TitleText.Text, DetailText.Text  
                , IsHtmlCheckBox.Checked, TicketCreatedByUserIDText.Text, OwnerText.Text, UserAssignTo  
                , CurrentStatusText.Text, CurrentStatusSetByText.Text, PriorityId, AffectsCustomerCheckBox.Checked  
                , PublishedToKbCheckBox.Checked, CompanyId, PercentageCompleted, ActiveText.Checked  
                , TicketCreatedByUserID, projectId, ProjectGroupId, startdate, endDate);  
         
    }  
}  

 

Tickets.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Tickets.ascx.cs" Inherits="Component_DAL_Tickets" %>  
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>  
<style type="text/css">  
    .style3  
    {  
        width: 100%;  
    }  
    .style4  
    {  
        width: 145px;  
    }  
    .style5  
    {  
        width: 170px;  
    }  
    .style6  
    {  
        width: 147px;  
    }  
    .style7  
    {  
        width: 275px;  
    }  
    .style8  
    {  
        width: 299px;  
    }  
</style>  
<table class="style3">  
    <tr>  
        <td class="style4">  
            <asp:Label ID="ParentTicketIdLabel" runat="server" Text="Parent Id"></asp:Label>  
        </td>  
        <td class="style5">  
            <asp:TextBox ID="ParentTicketIdText" runat="server"  
             ></asp:TextBox>  
        </td>  
        <td class="style6">  
            <asp:Label ID="PriorityIdLabel" runat="server" Text="Priority Id"></asp:Label>  
        </td>  
        <td class="style8">  
            <asp:TextBox ID="PriorityIdText" runat="server"  
             ></asp:TextBox>  
        </td>  
        <td class="style7">  
            <asp:Label ID="TicketCreatedByUserIDLabel" runat="server"   
                Text="Ticket Created By User"></asp:Label>  
        </td>  
        <td>  
            <asp:TextBox ID="TicketCreatedByUserIDText" runat="server"></asp:TextBox>  
        </td>  
    </tr>  
    <tr>  
        <td class="style4">  
            <asp:Label ID="TitleLabel" runat="server" Text="Title"></asp:Label>  
        </td>  
        <td class="style5">  
            <asp:TextBox ID="TitleText" runat="server"   
           ></asp:TextBox>  
        </td>  
        <td class="style6">  
            <asp:Label ID="AffectsCustomerLabel" runat="server" Text="Affects Customer"></asp:Label>  
        </td>  
        <td class="style8">  
            <asp:CheckBox ID="AffectsCustomerCheckBox" runat="server"   
             />  
        </td>  
        <td class="style7">  
            <asp:Label ID="ProjectIdLabel" runat="server" Text="Project Id"></asp:Label>  
        </td>  
        <td>  
            <asp:TextBox ID="ProjectIdText" runat="server"></asp:TextBox>  
        </td>  
    </tr>  
    <tr>  
        <td class="style4">  
            <asp:Label ID="IsHtmlLabel" runat="server" Text="Is Html"></asp:Label>  
        </td>  
        <td class="style5">  
              
            <asp:CheckBox ID="IsHtmlCheckBox" runat="server"   
             />  
        </td>  
        <td class="style6">  
            <asp:Label ID="PublishToKbLabel" runat="server" Text="Published To KB"></asp:Label>  
        </td>  
        <td class="style8">  
        <asp:CheckBox ID="PublishedToKbCheckBox" runat="server"/>  
              
        </td>  
        <td class="style7">  
            <asp:Label ID="ProjectGroupIdLabel" runat="server" Text="Project Group Id"></asp:Label>  
        </td>  
        <td>  
            <asp:TextBox ID="ProjectGroupIdText" runat="server"></asp:TextBox>  
        </td>  
    </tr>  
    <tr>  
        <td class="style4">  
            <asp:Label ID="OwnerLabel" runat="server" Text="Owner"></asp:Label>  
        </td>  
        <td class="style5">  
            <asp:TextBox ID="OwnerText" runat="server" ></asp:TextBox>  
        </td>  
        <td class="style6">  
            <asp:Label ID="CompanyIdLabel" runat="server" Text="Company Id"></asp:Label>  
        </td>  
        <td class="style8">  
            <asp:TextBox ID="CompanyIdText" runat="server"></asp:TextBox>  
        </td>  
        <td class="style7">  
            <asp:Label ID="StartDateLabel" runat="server" Text="Start Date"></asp:Label>  
        </td>  
        <td>  
            <asp:TextBox ID="StartDateText" runat="server"></asp:TextBox>  
        </td>  
    </tr>  
    <tr>  
        <td class="style4">  
            <asp:Label ID="UserAssignToLabel" runat="server" Text="User Assign To"></asp:Label>  
        </td>  
        <td class="style5">  
            <asp:TextBox ID="UserAssignToText" runat="server" ></asp:TextBox>  
        </td>  
        <td class="style6">  
            <asp:Label ID="PercentageCompleteLabel" runat="server"   
                Text="Percentage Complete"></asp:Label>  
        </td>  
        <td class="style8">  
            <asp:TextBox ID="PercentageCompleteText" runat="server"></asp:TextBox>  
        </td>  
        <td class="style7">  
            <asp:Label ID="EndDateLabel" runat="server" Text="End Date"></asp:Label>  
        </td>  
        <td>  
            <asp:TextBox ID="EndDateText" runat="server"></asp:TextBox>  
        </td>  
    </tr>  
    <tr>  
        <td class="style4">  
            <asp:Label ID="CurrentStatusSetByLabel" runat="server"   
                Text="Current Status SetBy"></asp:Label>  
        </td>  
        <td class="style5">  
            <asp:TextBox ID="CurrentStatusSetByText" runat="server" ></asp:TextBox>  
        </td>  
        <td class="style6">  
            <asp:Label ID="ActiveLabel" runat="server" Text="Active"></asp:Label>  
        </td>  
        <td class="style8">  
            <asp:CheckBox ID="ActiveText" runat="server" />  
        </td>  
        <td class="style7">  
            <asp:Label ID="CurrentStatusLabel" runat="server" Text="CurrentStatus"></asp:Label>  
        </td>  
        <td>  
            <asp:TextBox ID="CurrentStatusText" runat="server"></asp:TextBox>  
        </td>  
    </tr>  
    <tr>  
        <td class="style4">  
            &nbsp;</td>  
        <td class="style5">  
            &nbsp;</td>  
        <td class="style6">  
            &nbsp;</td>  
        <td class="style8">  
            &nbsp;</td>  
        <td class="style7">  
            &nbsp;</td>  
        <td>  
            &nbsp;</td>  
    </tr>  
    <tr>  
        <td class="style4">  
            <asp:Label ID="DetailLabel" runat="server" Text="Details"></asp:Label>  
        </td>  
        <td class="style5">  
              
            <asp:TextBox id="DetailText"   
            runat="server" TextMode="MultiLine" Rows="5" Columns="40" tabIndex="3"   
                Width="206px"></asp:TextBox>  
        </td>  
        <td class="style6">  
            &nbsp;</td>  
        <td class="style8">  
            &nbsp;</td>  
        <td class="style7">  
            &nbsp;</td>  
        <td>  
            &nbsp;</td>  
    </tr>  
    <tr>  
        <td class="style4">  
              
            <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'  
            runat="server"   
                  
                  
                CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>' onclick="btnUpdate_Click"   
                >  
           </asp:Button>  
           </td>  
        <td class="style5">  
           <asp:button id="btnCancel" text="<%$ Resources:Main, Cancel %>" Ref="Cancel" runat="server" causesvalidation="False"   
                commandname="Cancel" ></asp:button>  
        </td>  
        <td class="style6">  
            &nbsp;</td>  
        <td class="style8">  
            &nbsp;</td>  
        <td class="style7">  
            &nbsp;</td>  
        <td>  
            &nbsp;</td>  
    </tr>  
    <tr>  
        <td class="style4">  
            &nbsp;</td>  
        <td class="style5">  
            &nbsp;</td>  
        <td class="style6">  
            &nbsp;</td>  w
        <td class="style8">  
            &nbsp;</td>  
        <td class="style7">  
            &nbsp;</td>  
        <td>  
            &nbsp;</td>  
    </tr>  
</table>  
 
 

2 Answers, 1 is accepted

Sort by
0
Nikita Gourme
Top achievements
Rank 1
answered on 22 Aug 2008, 12:12 PM
It seems that you use some kind of mixture of update/insert logic when having user control edit form for the grid. When you use such type of edit form, you can not have automatic editing, therefore wiring the ItemUpdated/ItemInserted events is not meaningful. Instead consider using NeedDataSource binding and update/insert/delete items manually hooking the UpdateCommand/InsertCommand/DeleteCommand events of the grid.

Take this demo as a starting point if you like:

http://www.telerik.com/demos/aspnet/prometheus/Grid/Examples/DataEditing/UserControlEditForm/DefaultCS.aspx

Nikita
0
DragonBall
Top achievements
Rank 1
answered on 22 Aug 2008, 01:15 PM
thanx for the reply nikita

but i want to bind my data through tha ticket.axcs.cs not on ticketcs.acxs

ticket.ascx.cs:
PriorityIdText.Text = Convert.ToString(TicketEntity.MwsTickets.PriorityId); 

not like databinder.eval

ticketcs.ascx
<asp:TextBox id=TextBox3 Text='<%# DataBinder.Eval( Container, "DataItem.LastName") %>' runat="server" tabIndex=9>
  </asp:textbox></td>


how do it on the backend of ascx it wont bind?
Tags
Grid
Asked by
DragonBall
Top achievements
Rank 1
Answers by
Nikita Gourme
Top achievements
Rank 1
DragonBall
Top achievements
Rank 1
Share this question
or