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

how to set sqldatasource parameter from the telerikgridcolumn

1 Answer 401 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sireesha
Top achievements
Rank 1
Sireesha asked on 28 Feb 2014, 12:45 PM
Hi,

I am trying to bind gridcolumn to sqldatasource through wizrard it is showing only grid name but not column details to add to parameter.
Please find my code.
Here is my aspx Page.
SystemID is the columnname in the grid that i need to set in sqldatasource.
<tr>
    <td class="td" width="100%" align="center">
        <table width="100%" align="center">
            <tr>
                <td class="td" width="100%" align="center">
                    <telerik:RadGrid ID="rgMunicipality" runat="server" GridLines="None" AllowPaging="True"
                        AllowAutomaticUpdates="True" AllowAutomaticInserts="True" AllowSorting="True"
                        Width="750px" CellSpacing="0" AutoGenerateColumns="False">
                        <%-- OnItemCommand="rgMunicipality_ItemCommand">--%>
                        <%-- OnUpdateCommand="rgMunicipality_InsertCommand"
                OnInsertCommand="rgMunicipality_InsertCommand">--%>
                        <PagerStyle Mode="NextPrev" />
                        <MasterTableView DataKeyNames="SystemID" CommandItemDisplay="Top" GridLines="None"
                            AllowAutomaticDeletes="False">
                            <%-- EditMode="InPlace"--%>
                            <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
                            <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
                            </RowIndicatorColumn>
                            <ExpandCollapseColumn Visible="False">
                                <HeaderStyle Width="19px" />
                            </ExpandCollapseColumn>
                            <%--<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
                    </ExpandCollapseColumn>--%>
                            <Columns>
                                <telerik:GridEditCommandColumn>
                                </telerik:GridEditCommandColumn>
                                <telerik:GridBoundColumn DataField="SystemID" HeaderText="SystemID" SortExpression="PriorityID"
                                    UniqueName="SystemID" Visible="False" MaxLength="5" FilterControlAltText="Filter SystemID column">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="SystemName" HeaderText="Name" SortExpression="SystemName"
                                    UniqueName="SystemName" FilterControlAltText="Filter SystemName column">
                                </telerik:GridBoundColumn>
                                 <telerik:GridDropDownColumn DataField="Manager" HeaderText="Manager"  ListValueField="ManagerID" ListTextField="Manager"
                                      EmptyListItemText="--Choose an option--" EmptyListItemValue=""
                                    UniqueName="Manager" SortExpression="Manager" DataSourceID="SQLDataSource6">
                                </telerik:GridDropDownColumn>
                                <telerik:GridCheckBoxColumn DataField="Enabled" DataType="System.Boolean" FilterControlAltText="Filter Enabled column"
                                    HeaderText="Enabled" SortExpression="Enabled" UniqueName="Enabled">
                                </telerik:GridCheckBoxColumn>
                            </Columns>
                            <EditFormSettings EditFormType="Template">
                                <FormTemplate>
                                    <table id="tblSystemEdit" runat="server" cellpadding="0" cellspacing="0" style="width: 100%;
                                        height: 100%;" border="0">
                                        <tr>
                                            <td valign="middle" style="height: 26px; background-color: #DDE1E6;" align="left"
                                                colspan="2">
                                                  <asp:Label ID="lblSubHeading" runat="server" CssClass="clsFormTemplateHeader"
                                                    Text="Details"></asp:Label>
                                            </td>
                                            <td style="width: 5px; text-align: right; background-color: #DDE1E6; height: 26px;"
                                                align="right">
                                            </td>
                                        </tr>
                                        <tr>
                                            <td valign="top" style="width: 30px; height: 22px;">
                                            </td>
                                            <td valign="top" align="left">
                                                <table style="width: 310px; height: 70px; margin-left: 260px;" class="clsTestTable">
                                                    <tr>
                                                        <td style="text-align: right; width: 150px; height: 18px;">
                                                            <asp:Label ID="lblName" runat="server">Name</asp:Label>
                                                        </td>
                                                        <td style="width: 200px; text-align: left; height: 18px;">
                                                            <div style="float: left; padding-right: 5px">
                                                                <asp:TextBox ID="txtName" runat="server" MaxLength="50" Width="145px" Text='<%# Bind( "SystemName") %>'
                                                                    Rows="2"></asp:TextBox></div>
                                                            <asp:RequiredFieldValidator ID="rfvName" runat="server" ControlToValidate="txtName"
                                                                ErrorMessage="Name is required" ValidationGroup="PersonalInfo">*</asp:RequiredFieldValidator>
                                                            <asp:TextBox ID="txtSystemID" runat="server" MaxLength="50" Width="145px" Text='<%# Bind( "SystemID") %>'
                                                                Visible="false"></asp:TextBox>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td style="width: 150px; height: 18px; text-align: right">
                                                            <asp:Label ID="lblManager" runat="server">Manager</asp:Label>
                                                        </td>
                                                        <td style="width: 200px; height: 18px; text-align: left">
                                                            <div style="float: left; padding-right: 5px">
                                                                <telerik:RadComboBox ID="ddlManager" runat="server" Width="144px" Skin="Default"
                                                                    EnableEmbeddedSkins="true" DataSourceID="SQLDataSource6" DataTextField="Manager"
                                                                    DataValueField="ManagerID" SelectedValue='<%# DataBinder.Eval(Container.DataItem, "Manager")%>'>
                                                                </telerik:RadComboBox>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td style="width: 150px; height: 18px; text-align: right">
                                                            <asp:Label ID="lblEnabled" runat="server">Enabled</asp:Label>
                                                        </td>
                                                        <td style="width: 200px; height: 18px; text-align: left">
                                                            <div style="float: left; padding-right: 5px">
                                                                <asp:CheckBox ID="chkEnabled" runat="server" Checked='<%# If(IsDBNull(Eval("Enabled")), False, Eval("Enabled"))  %>' /></div>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                            <td>
                                                  
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="2" style="height: 40px; background-color: #DDE1E6; text-align: center;">
                                                <div id="Zone1">
                                                    <asp:Button ID="btnUpdate" Text='<%# If(CBool(DataBinder.Eval(Container, "OwnerTableView.IsItemInserted")), "Insert", "Update") %>'
                                                        runat="server" CausesValidation="True" CommandName='<%# If(CBool(DataBinder.Eval(Container, "OwnerTableView.IsItemInserted")), "PerformInsert", "Update") %>'
                                                        Width="145px" ValidationGroup="PersonalInfo" /> 
                                                    <asp:Button ID="btnCancel" runat="server" CausesValidation="False" CommandName="Cancel"
                                                        Text="Cancel" Width="145px" /></div>
                                            </td>
                                            <td style="background-color: #DDE1E6;">
                                                  
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                            </td>
                                            <td style="text-align: left">
                                                <asp:ValidationSummary ID="ValidationSummary2" runat="server" ValidationGroup="PersonalInfo"
                                                    Width="250px" DisplayMode="BulletList" />
                                            </td>
                                            <td>
                                            </td>
                                        </tr>
                                    </table>
                                </FormTemplate>
                                <FormCaptionStyle BorderStyle="Solid" />
                                <FormStyle BackColor="#F2F2F2" BorderColor="#BEBEBE" BorderStyle="Solid" BorderWidth="1px" />
                            </EditFormSettings>
                        </MasterTableView>
                        <FilterMenu EnableImageSprites="False">
                            <WebServiceSettings>
                                <ODataSettings InitialContainerName="">
                                </ODataSettings>
                            </WebServiceSettings>
                        </FilterMenu>
                        <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
                            <WebServiceSettings>
                                <ODataSettings InitialContainerName="">
                                </ODataSettings>
                            </WebServiceSettings>
                        </HeaderContextMenu>
                    </telerik:RadGrid>
                </td>
            </tr>
            <tr>
                <td class="td">
                    <input type="hidden" name="item_list" />
                        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:IssueManagerConnectionString %>"
                            SelectCommand="Users_getUsersByDepartment" SelectCommandType="StoredProcedure">
                            <SelectParameters>
                                <asp:Parameter DefaultValue="1" Name="SystemID" Type="Int32" />
                            </SelectParameters>
                        </asp:SqlDataSource>
                    </center>
                </td>
            </tr>
            <tr>
                <td class="td" align="center">
                    <asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True"
                        ShowSummary="False" DisplayMode="List"></asp:ValidationSummary>
                    <div style="text-align: center; width: 100%">
                    </div>
                </td>
            </tr>
        </table>
    </td>
</tr>

Here is the my stored procedure.
ALTER PROCEDURE [dbo].[Users_getUsersByDepartment]
    @SystemID INT
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
 
     SELECT FirstName + LastName AS Manager,
     UserID AS ManagerID
     FROM IM_System a INNER JOIN Users_UserDetail b ON  a.SystemID=b.SystemID
     WHERE b.SystemID=@SystemID
END

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 05 Mar 2014, 10:16 AM
Hello,

When using declarative data source for RadGrid you need to set the DataSourceID for the grid and the MasterTableView.

There is an illustration on how this could be setup in this article. It also shows how to setup the parameters for the data source.

Regards,
Viktor Tachev
Telerik

DevCraft Q1'14 is here! Join the free online conference to see how this release solves your top-5 .NET challenges. Reserve your seat now!

Tags
Grid
Asked by
Sireesha
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or