Click here to Skip to main content
15,850,750 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working with RadGrid.RadGrid fill by SqlDataSource But when i want Grid to be used only for Inserting new records and RadGrid data set is empty,the grid is not visible,only a single line appears in the web page
Please help me
Thanks
C#
<telerik:RadGrid ID="RadGrid3"   runat="server"   AutoGenerateEditColumn="True" ShowFooter="true"
            GridLines="None" AllowAutomaticUpdates="True" AllowAutomaticDeletes="True"
        AllowAutomaticInserts="True"    OnItemDeleted="RadGrid2_ItemDeleted"
        OnItemInserted="RadGrid2_ItemInserted" 
        OnItemUpdated="RadGrid2_ItemUpdated" AutoGenerateDeleteColumn="True" 
        Skin="Office2007" 
        AllowSorting="True" AutoGenerateColumns="False"
        ShowStatusBar="True" onitemcommand="RadGrid3_ItemCommand" 
      
        oninsertcommand="RadGrid3_InsertCommand" 
        onitemdatabound="RadGrid3_ItemDataBound" 
        onselectedindexchanged="RadGrid3_SelectedIndexChanged" 
        ondatabound="RadGrid3_DataBound" onupdatecommand="RadGrid3_UpdateCommand" onneeddatasource="RadGrid3_NeedDataSource" 
            DataSourceID="SqlDataSource3" Enabled="False" 
               öndatabinding="RadGrid3_DataBinding">
        <ClientSettings EnablePostBackOnRowClick="True">
               
            <Selecting AllowRowSelect="True" />
             <ClientEvents  önRowDblClick="RowDblClick"></ClientEvents>
        </ClientSettings>
        <MasterTableView  CommandItemDisplay="Top"  EditMode="PopUp"  
            DataKeyNames="WorkID" DataSourceID="SqlDataSource3" >
            <CommandItemSettings AddNewRecordText="ایجاد" RefreshText="به روز رسانی"   />
            <Columns>
                <telerik:GridBoundColumn DataField="MachinaryMainCode" 
                    HeaderText="MachinaryMainCode" SortExpression="MachinaryMainCode" 
                    UniqueName="MachinaryMainCode" Visible="False">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="UserDate" DataType="System.DateTime" 
                    HeaderText="UserDate" SortExpression="UserDate" 
                    UniqueName="UserDate" Visible="False">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="WorkDuration" DataType="System.Int32" 
                    HeaderText="مدت زمان کارکرد" SortExpression="WorkDuration" 
                    UniqueName="WorkDuration">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="WorkID" DataType="System.Int32" 
                    HeaderText="WorkID" SortExpression="WorkID" 
                    UniqueName="WorkID" ReadOnly="True" Visible="False">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="URID" 
                    HeaderText="URID" SortExpression="URID" 
                    UniqueName="URID" DataType="System.Int32" ReadOnly="True" Visible="False">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="UnUsaReason" 
                    HeaderText="علت بیکاری" SortExpression="UnUsaReason" 
                    UniqueName="UnUsaReason">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="USID" DataType="System.Int32" 
                    HeaderText="USID" SortExpression="USID" 
                    UniqueName="USID" ReadOnly="True" Visible="False">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="UsageName" 
                    HeaderText="محل استفاده" SortExpression="UsageName" 
                    UniqueName="UsageName">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="StatusID" DataType="System.Int32" 
                    HeaderText="StatusID" ReadOnly="True" SortExpression="StatusID" 
                    UniqueName="StatusID" Visible="False">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="StatusName" HeaderText="وضعیت" 
                    SortExpression="StatusName" UniqueName="StatusName">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="EPID" DataType="System.Int32" 
                    HeaderText="EPID" ReadOnly="True" SortExpression="EPID" UniqueName="EPID" 
                    Visible="False">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="EquipmentName" HeaderText="تجهیز" 
                    SortExpression="EquipmentName" UniqueName="EquipmentName">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="ARID" DataType="System.Int32" 
                    HeaderText="ARID" ReadOnly="True" SortExpression="ARID" UniqueName="ARID" 
                    Visible="False">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="AreaName" HeaderText="ناحیه" 
                    SortExpression="AreaName" UniqueName="AreaName">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="WorkKilometer" DataType="System.Int32" 
                    HeaderText="کیلومتر" SortExpression="WorkKilometer" 
                    UniqueName="WorkKilometer">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="ContractorID" DataType="System.Int32" 
                    HeaderText="ContractorID" ReadOnly="True" SortExpression="ContractorID" 
                    UniqueName="ContractorID" Visible="False">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="CompanyName" HeaderText="شرکت پیمانکار" 
                    SortExpression="CompanyName" UniqueName="CompanyName">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Name" HeaderText="نام پیمانکار" 
                    SortExpression="Name" UniqueName="Name">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="UnUsaReasonID" DataType="System.Int32" 
                    HeaderText="UnUsaReasonID" SortExpression="UnUsaReasonID" 
                    UniqueName="UnUsaReasonID" Visible="False">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="ContractorType" HeaderText="ContractorType" 
                    SortExpression="ContractorType" UniqueName="ContractorType" 
                    Visible="False">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="DisciplineID" DataType="System.Int32" 
                    HeaderText="DisciplineID" SortExpression="DisciplineID" 
                    UniqueName="DisciplineID" Visible="False">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="DisciplineName" HeaderText="دیسیپلین" 
                    SortExpression="DisciplineName" UniqueName="DisciplineName">
                </telerik:GridBoundColumn>
            </Columns>
    <EditFormSettings  InsertCaption="اضافه کردن کارکرد" CaptionFormatString="تغییر اطلاعات کارکرد"
                EditFormType="Template" PopUpSettings-Modal="true"   CaptionDataField="MachinaryMainCode">
    <FormTemplate>
                    <table id="Table1" cellspacing="1" cellpadding="1" width="250" border="0">
                   
                        <tr>
                        <td>
                        <asp:label id="lblWorkID" runat="server"    Text='<%# Bind("WorkID") %>'></asp:label>
                        <asp:label id="lblContractorID" runat="server"    Text='<%# Bind("ContractorID") %>'></asp:label>
                        
                        </td>
                        </tr>
                        <tr>
                            <td class="style3">
                                محل استفاده:</td>
                            <td>
                            
                                   <asp:DropDownList ID="drpUsageshop" runat="server" AppendDataBoundItems="True" 
                                        
                                       Width="115px" DataSourceID="UsageShopSqlDataSource" 
                                       DataTextField="UsageName" DataValueField="ID" 
                                       SelectedValue='<%# Bind("USID") %>'>
                                       <asp:ListItem Text="انتخاب کنید" Value="" Selected="True"> </asp:ListItem>
                                   </asp:DropDownList>
                            </td>
                        </tr>
                        <tr>
                            
                            <td class="style3">
                                وضعیت ماشین:
                            </td>
                            <td>
                                <asp:DropDownList ID="drpMachinStatus" runat="server" 
                                    AppendDataBoundItems="True" DataSourceID="MachinStatusSqlDataSource" 
                                    DataTextField="StatusName" DataValueField="StatusID" 
                                    SelectedValue='<%# Bind("StatusID") %>' Width="115px">
                                    <asp:ListItem  Text="انتخاب کنید" Value=""> </asp:ListItem>
                                </asp:DropDownList>
                            </td>
                        </tr>
                        <tr>
                            <td class="style3">
                                علت مصرف نشدن:
                            </td>
                            <td>
                                <asp:DropDownList ID="drpUnUse" runat="server" AppendDataBoundItems="True" 
                                    DataSourceID="UnUseSqlDataSource" DataTextField="UnUsaReason" 
                                    DataValueField="ID" SelectedValue='<%# Bind("URID") %>' Width="115px">
                                    <asp:ListItem Text="انتخاب کنید" Value=""> </asp:ListItem>
                                </asp:DropDownList>
                            </td>
                        </tr>
                        <tr>
                            <td class="style3">
                                تجهیز:
                            </td>
                            <td>
                                <asp:DropDownList ID="EquipmentDropDown" runat="server" 
                                    AppendDataBoundItems="True" DataSourceID="EquipmentSqlDataSource" 
                                    DataTextField="EquipmentName" DataValueField="ID" 
                                    SelectedValue='<%# Bind("EPID") %>' Width="115px">
                                    <asp:ListItem  Text="انتخاب کنید" Value=""> </asp:ListItem>
                                </asp:DropDownList>
                            </td>
                        </tr>
                        <tr>
                            <td class="style3">
                                ناحیه:
                            </td>
                            <td>
                                <asp:DropDownList ID="drpArea" runat="server" AppendDataBoundItems="True" 
                                    DataSourceID="AreaSqlDataSource" DataTextField="AreaName" DataValueField="ID" 
                                    SelectedValue='<%# Bind("ARID") %>' Width="115px">
                                    <asp:ListItem Text="انتخاب کنید" Value=""></asp:ListItem>
                                </asp:DropDownList>
                            </td>
                        </tr>
                        <tr>
                            <td class="style3">
                                دیسیپلین:
                            </td>
                            <td>
                                <asp:DropDownList ID="DeciplinDropDownList" runat="server" 
                                    AppendDataBoundItems="True" DataSourceID="DeciplinSqlDataSource" 
                                    DataTextField="DisciplineName" DataValueField="ID" 
                                    SelectedValue='<%# Bind("DisciplineID") %>' Width="115px">
                                    <asp:ListItem Text="انتخاب کنید" Value=""></asp:ListItem>
                                </asp:DropDownList>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <hr />
                            </td>
                            <tr>
                                <td class="style3">
                                    پیمانکار:
                                </td>
                                <td>
                                    <asp:DropDownList ID="DropDownListContractorType" runat="server" 
                                        AppendDataBoundItems="True" AutoPostBack="True" 
                                        onselectedindexchanged="DropDownListContractorType_SelectedIndexChanged" 
                                        SelectedValue='<%# Bind("ContractorType") %>' Width="115px">
                                        <asp:ListItem Selected="True" Text="انتخاب کنید" Value=""></asp:ListItem>
                                        <asp:ListItem Value="A">حقیقی</asp:ListItem>
                                        <asp:ListItem Value="O">حقوقی</asp:ListItem>
                                    </asp:DropDownList>
                                    <asp:DropDownList ID="ContrctorDropDownList" runat="server"
                                        AppendDataBoundItems="True" Width="115px">
                                        <asp:ListItem Selected="True" Text="انتخاب کنید" Value=""> </asp:ListItem>
                                    </asp:DropDownList>
                                </td>
                                <td>
                                    <hr />
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <hr />
                                </td>
                        
                                <tr>
                                    <td class="style3">
                                        ساعت کارکرد:</td>
                                    <td>
                                        <asp:TextBox ID="txtworkDeuration" runat="server" 
                                            Text='<%# Bind("WorkDuration") %>' Width="104px" onkeypress="return isNumberKey(event)"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
                                            ControlToValidate="txtworkDeuration" ForeColor="Red" Text="*" 
                                            ValidationGroup="ValidationGroup"></asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="style3">
                                        کیلومتر کارکرد:</td>
                                    <td>
                                        <asp:TextBox ID="txtkilometer" runat="server" 
                                            Text='<%# Bind("WorkKilometer") %>' Width="104px" onkeypress="return isNumberKey(event)"></asp:TextBox>
                                    </td>
                                </tr>
                            </tr>
                        </tr>
                  
                    </table>
                    <table style="width: 100%">
                    <tr>
                    <td>
                    <center>
                      <asp:ValidationSummary ID="ValidationSummary1" runat="server" 
                           DisplayMode="SingleParagraph" ForeColor="Red" 
                           HeaderText="اطلاعات مشخص شده را وارد نمایید" 
                           ValidationGroup="ValidationGroup" />
                           </center>
                    </td>
                    </tr>
                        <tr>
                            <td align="right">
                                <asp:Button ID="Button1" Text='<%# (Container is GridEditFormInsertItem) ? "ایجاد" : "بروزرسانی" %>'
                                CommandName='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                    runat="server" ValidationGroup="ValidationGroup"  >
                                </asp:Button> 
                                <asp:Button ID="Button2" Text="انصراف" runat="server" CausesValidation="False" CommandName="Cancel">
                                </asp:Button>
                            </td>
                        </tr>
                    </table>
                </FormTemplate>
        <PopUpSettings Modal="True" />
    </EditFormSettings>
    
        </MasterTableView>
        <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
    </telerik:RadGrid>
 <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
            ConnectionString="<%$ ConnectionStrings:CMMSConnectionString2 %>" 
            
        SelectCommand="SELECT ML.MachinaryMainCode, WI.UserDate, WI.WorkDuration, WI.WorkID, UR.ID AS URID, UR.UnUsaReason, US.ID AS USID, US.UsageName, MS.StatusID, MS.StatusName, EP.ID AS EPID, EP.EquipmentName, Ar.ID AS ARID, Ar.AreaName, WI.WorkKilometer, CN.ContractorID, CN.CompanyName, CN.Name + ' ' + CN.Family AS Name, WI.UnUsaReasonID, CN.ContractorType, WI.DisciplineID, Discipline.DisciplineName FROM Discipline RIGHT OUTER JOIN WorkInfo AS WI ON Discipline.ID = WI.DisciplineID RIGHT OUTER JOIN MachinList AS ML LEFT OUTER JOIN MachineryName AS MN ON ML.MachinaryNameID = MN.ID LEFT OUTER JOIN MachineryModel AS MM ON ML.MachinaryModelID = MM.ID LEFT OUTER JOIN MachineryType AS MT ON ML.MachinaryTypeID = MT.ID ON WI.MachinID = ML.ID LEFT OUTER JOIN UnUsaReason AS UR ON WI.UnUsaReasonID = UR.ID LEFT OUTER JOIN UsageShop AS US ON WI.UsageShopID = US.ID LEFT OUTER JOIN MachinStatus AS MS ON WI.StatusID = MS.StatusID LEFT OUTER JOIN Equipment AS EP ON WI.EquipmentID = EP.ID LEFT OUTER JOIN Area AS Ar ON WI.AreaID = Ar.ID LEFT OUTER JOIN Contractor AS CN ON WI.ContractorID = CN.ContractorID WHERE (ML.ID = @ID) AND (WI.UserDate = @UserDate or WI.UserDate is null )" 
        onselected="SqlDataSource3_Selected">
            <SelectParameters>
                <asp:ControlParameter ControlID="RadGrid1" Name="ID" 
                    PropertyName="SelectedValues['ID']" />
                <asp:ControlParameter ControlID="DatePicker1" Name="UserDate" 
                    PropertyName="Date" Type="DateTime" />
            </SelectParameters>
        </asp:SqlDataSource>
Posted
Updated 9-Dec-12 0:20am
v2
Comments
[no name] 9-Dec-12 5:13am    
provide your code ..

1 solution

U should use OnNeedDatasourse event and write the code to fill your grid from SQL inside the event.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900