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

[Solved] Grid in UserControl

5 Answers 178 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jack Guan
Top achievements
Rank 1
Jack Guan asked on 11 Aug 2009, 01:06 AM
I creat a Grid in usercontrol and set the DataSource is Dataset.But Can't insert a new record when post!
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="AssemblyControl.ascx.vb" Inherits="Module_FloorControl_AssemblyControl"%>  
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>  
<table width="100%" border="0" cellspacing="0" cellpadding="10" style="border: 1px solid #C0C0C0; font-family: Verdana; font-size: 10px; color: #4A535B; font-weight: bold;">  
  <tr>  
    <td bgcolor="#F3F3F1"><table width="100%" border="0" cellspacing="5" cellpadding="0">  
  <tr>  
    <td width="80" height="25" align="right" >*Model:</td>  
    <td width="500" valign="middle" >  
        <telerik:RadTextBox ID="ModelTxt" Runat="server" Skin="Default" LabelCssClass="radLabelCss_Gray"   
            Width="125px" Enabled="False">        </telerik:RadTextBox>          </td>  
    <td valign="middle" >&nbsp;</td>  
  </tr>  
  <tr>  
    <td width="80" height="25" align="right" >*PCBA:</td>  
    <td width="500" valign="middle" >  
        <telerik:RadTextBox ID="PCBATxt" Runat="server" Skin="Default" LabelCssClass="radLabelCss_Gray"   
            Width="125px">        </telerik:RadTextBox>          </td>  
    <td valign="middle" >&nbsp;</td>  
  </tr>  
  <tr>  
    <td width="80" height="25" align="right" >*Description:</td>  
    <td width="500" valign="middle" >  
                <telerik:RadTextBox ID="DescriptionTxt" Runat="server" Skin="Default" LabelCssClass="radLabelCss_Gray"   
                    Width="200px">        </telerik:RadTextBox>          </td>  
    <td valign="middle" >&nbsp;</td>  
  </tr>  
  <tr>  
    <td width="80" height="25" align="right" >Mother Board:</td>  
    <td width="500" valign="middle" >  
                  <telerik:RadComboBox ID="MotherBoardDdl" Runat="server" Skin="Default">  
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>  
                  </telerik:RadComboBox>  
      </td>  
    <td valign="middle" >&nbsp;</td>  
  </tr>  
  <tr>  
    <td width="80" height="25" align="right" >Main Board: </td>  
    <td width="500" valign="middle" >  
                  <asp:CheckBox ID="MBCHK" runat="server" />  
      </td>  
    <td valign="middle" >&nbsp;</td>  
  </tr>  
  <tr>  
    <td width="80" height="25" align="right" >Remarks:</td>  
    <td width="500" valign="middle" >  
               <telerik:RadTextBox ID="RemarksTxt" Runat="server" Skin="Default"   
                   LabelCssClass="radLabelCss_Gray" Width="370px"   
                   Columns="50" Height="80px" TextMode="MultiLine">        </telerik:RadTextBox>          </td>  
    <td valign="middle" >&nbsp;</td>  
  </tr>  
   <tr>  
    <td align="center" ></td>  
    <td align="left" colspan="2" >  
        <telerik:RadGrid ID="RadGrid1" runat="server" Skin="Hay" GridLines="None" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" Width="97%" PageSize="10" 
            AllowAutomaticUpdates="True" AllowPaging="True" AutoGenerateColumns="False"  OnInsertCommand="RadGrid1_InsertCommand">  
 
<MasterTableView Width="100%" CommandItemDisplay="Top" DataKeyNames="SeqNo" 
               HorizontalAlign="NotSet" AutoGenerateColumns="False">  
<Columns>  
                    <telerik:GridClientSelectColumn HeaderStyle-Width="40px" >  
<HeaderStyle Width="40px"></HeaderStyle>  
                    </telerik:GridClientSelectColumn>  
                     <telerik:GridBoundColumn DataField="Model" HeaderText="Model" SortExpression="Model" UniqueName="Model" EditFormColumnIndex="0">  
                    </telerik:GridBoundColumn>  
                    <telerik:GridBoundColumn DataField="PCBA" HeaderText="PCBA"  UniqueName="PCBA" EditFormColumnIndex="0">  
                    </telerik:GridBoundColumn>  
                    <telerik:GridBoundColumn DataField="SeqNo" HeaderText="Seq No" SortExpression="SeqNo" UniqueName="SeqNo" EditFormColumnIndex="1">  
                    </telerik:GridBoundColumn>  
                    <telerik:GridDropDownColumn DataField="Process"  HeaderText="Process" ListTextField="Process" ListValueField="Process" UniqueName="Process" EditFormColumnIndex="1" FilterListOptions="AllowAllFilters">  
                    </telerik:GridDropDownColumn>  
                    <telerik:GridDropDownColumn DataField="FailedUnitReturnTo" HeaderText="Failed To"   SortExpression="FailedUnitReturnTo" UniqueName="FailedUnitReturnTo" EditFormColumnIndex="2">  
                        </telerik:GridDropDownColumn>  
                      <telerik:GridDropDownColumn DataField="Label1" HeaderText="Label1"  EditFormColumnIndex="2">  
                        </telerik:GridDropDownColumn>      
                     <telerik:GridDropDownColumn DataField="Label2" HeaderText="Label2"  SortExpression="Label2" UniqueName="Label2" EditFormColumnIndex="3">  
                        </telerik:GridDropDownColumn>     
                         <telerik:GridDropDownColumn DataField="Label3" HeaderText="Label3"   SortExpression="Label3" UniqueName="Label3" EditFormColumnIndex="3">  
                        </telerik:GridDropDownColumn>         
                             </Columns>  
<SortExpressions>  
<telerik:GridSortExpression FieldName="SeqNo" SortOrder ="Ascending" />  
</SortExpressions>  
  <EditFormSettings ColumnNumber="4" CaptionDataField="PCBA" CaptionFormatString="Edit properties of Product {0}">  
                    <FormTableItemStyle Wrap="False"></FormTableItemStyle>  
                    <FormMainTableStyle GridLines="Horizontal" CellSpacing="0" CellPadding="3" BackColor="White" 
                        Width="100%" />  
                    <FormTableStyle CellSpacing="0" CellPadding="2" Height="60px" 
                        BackColor="White" />  
                    <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>  
                    <EditColumn ButtonType="ImageButton"   
                        InsertText="Insert Order" UpdateText="Update record" UniqueName="EditCommandColumn1" CancelText="Cancel edit">  
                    </EditColumn>  
                    <FormTableButtonRowStyle HorizontalAlign="Right"></FormTableButtonRowStyle>  
                </EditFormSettings>  
</MasterTableView>  
 
<FilterMenu EnableTheming="True">  
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>  
</FilterMenu>  
        </telerik:RadGrid>  
          </td>  
   </tr>  
   <tr>  
    <td align="center" ></td>  
    <td width="500" align="left" ><asp:Button ID="Button5" runat="server" Text="Save"   
            Font-Names="Verdana" CssClass="bButton"  />  
      
      &nbsp;<asp:Button ID="Button6" runat="server" Text="Cancel" CssClass="bButton" /></td>  
    <td align="center" ></td>  
   </tr>  
</table></td>  
  </tr>  
</table>  
    
 
   
Imports System.Data  
Imports Telerik.Web.UI  
Partial Class Module_FloorControl_AssemblyControl  
    Inherits System.Web.UI.UserControl  
    Dim eTraceWS As New eTraceReportService.Service  
    Dim ds As New Data.DataSet  
    Dim contorl As New Label  
    Dim LabelModule As New Label  
    Dim treeview As New Telerik.Web.UI.RadTreeView  
    Dim Assembly As String 
    Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles MyBase.Load  
        LabelModule = Me.Parent.Parent.FindControl("LabelMoudel")  
        contorl = Me.Parent.Parent.FindControl("LabelName")  
        treeview = Me.Parent.Parent.FindControl("ModuleTreeView")  
        Assembly = contorl.Text  
        ds = eTraceWS.GetAssemblyData(Assembly, treeview.SelectedNode.Text)  
        RestScreen()  
    End Sub 
    Public Sub RestScreen()  
        Dim process As New Telerik.Web.UI.GridDropDownColumn  
        If Assembly <> "" Then 
 
        Else 
            ModelTxt.Text = treeview.SelectedNode.Text  
            PCBATxt.Text = "" 
            DescriptionTxt.Text = "" 
            MotherBoardDdl.SelectedIndex = 0  
            MBCHK.Checked = False 
            RemarksTxt.Text = "" 
        End If 
    End Sub 
 
    Protected Sub RadGrid1_InsertCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.InsertCommand  
 
    End Sub 
 
    Protected Sub RadGrid1_ItemCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand  
 
    End Sub 
 
    Protected Sub RadGrid1_ItemInserted(ByVal source As ObjectByVal e As Telerik.Web.UI.GridInsertedEventArgs) Handles RadGrid1.ItemInserted  
 
    End Sub 
 
    Protected Sub RadGrid1_NeedDataSource(ByVal source As ObjectByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource  
        RadGrid1.DataSource = ds  
        RadGrid1.DataMember = "Routing" 
        RadGrid1.MasterTableView.DataSource = ds  
        RadGrid1.MasterTableView.DataMember = "Routing" 
    End Sub 
End Class 
How can i do ?

5 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 12 Aug 2009, 02:16 PM
Hi Jack Guan,

Do you have any errors? Generally automatic operations are supported only when the grid is bound to DataSourceControl!

Kind regards,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Jack Guan
Top achievements
Rank 1
answered on 13 Aug 2009, 02:01 AM
Hi Vlad :
It's no errors.I try it not in usercontrol, and debug it ,it can stop in RadGrid1_InsertCommand.but also can't add new row. And the dataset have no changed!
0
Jack Guan
Top achievements
Rank 1
answered on 13 Aug 2009, 04:05 AM
I just test another which in usercontrol but can run in RadGrid1_InsertCommand.
0
Shinu
Top achievements
Rank 2
answered on 13 Aug 2009, 05:56 AM
Hi Jack,

As Vlad pointed you will have to configure the respective data source control (including update/insert/delete parameters to its definition) to trigger the automatic operations. You can refer the following online demo for getting more details about performing automatic operations in RadGrid.
Automatic Operations

In your case I would suggest you to perform Insert operation manually from code behind as shown in the following help article.
Insert/Update/Delete at database level with queries

Thanks
Shinu
0
Jack Guan
Top achievements
Rank 1
answered on 14 Aug 2009, 06:20 AM
Hi Shinu:
I know as your said.But the problem not is your said. Now I depict the problem again.
when I click "New a record",It can fire event "RadGrid1_ItemCommand" and  e.CommandName = "InitInsert".
But I click "Insert order", It can't  catch the event .
Tags
Grid
Asked by
Jack Guan
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Jack Guan
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or