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

RadGrid+DataSourceID + custom commands

1 Answer 81 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Cata
Top achievements
Rank 1
Cata asked on 02 Feb 2020, 08:05 AM

Hi,

 

I have a grid where I defined 2 columns with custom commands. When I click those columns, the code runs at "....ItemCommand", BUT an automatic databind is somehow called (the database is called) and the grid is refreshed with data from the database.

My questions: is this the normal behavior? if yes, how can I prevent this?

 

<telerik:RadGrid ID="gvProgramareExamene" runat="server" DataSourceID="SqlDataSource1" OnItemDataBound="gvProgramareExamene_ItemDataBound" OnItemCommand="gvProgramareExamene_ItemCommand" AutoGenerateColumns="False" RenderMode="Lightweight">
                <groupingsettings collapsealltooltip="Collapse all groups"></groupingsettings>
                <exportsettings>
                    <pdf pagewidth="">
                    </pdf>
                </exportsettings>
                <mastertableview datakeynames="ID_AnUniv, ID_SesiuneExamene, ID_SesiuneExameneSpecializare,ID_DetaliuPlanSemestru,ID_DetaliuPlanSemestruStudent,ID_Specializare,ID_AnStud,ID_ProfesorTitularCurs,ID_ProgramareExamen,ID_Grupe,NoteFinalizate,NoteSalvate" clientdatakeynames="ID_AnUniv, ID_SesiuneExamene, ID_SesiuneExameneSpecializare,ID_DetaliuPlanSemestru,ID_Specializare,ID_AnStud,ID_ProfesorTitularCurs,ID_ProgramareExamen,ID_Grupe,ID_Materie,NoteFinalizate,NoteSalvate" datasourceid="SqlDataSource1" enablelinqgrouping="False" showfooter="True">
                    <rowindicatorcolumn visible="False">
                    </rowindicatorcolumn>
                    <expandcollapsecolumn created="True">
                    </expandcollapsecolumn>
                    <Columns>
                        <telerik:GridBoundColumn DataField="Denumire" FilterControlAltText="Filter Denumire column" HeaderText="Denumire" ReadOnly="True" SortExpression="Denumire" UniqueName="Denumire">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="NumarSemestruDinAn" DataType="System.Int32" FilterControlAltText="Filter NumarSemestruDinAn column" HeaderText="Semestrul" SortExpression="NumarSemestruDinAn" UniqueName="NumarSemestruDinAn">
                        </telerik:GridBoundColumn>

                        <telerik:GridTemplateColumn DataField="Data" DataType="System.DateTime" FilterControlAltText="Filter DataInceputPeSpec column" HeaderText="Data" SortExpression="Data" UniqueName="Data">
                            <ItemTemplate>
                                <asp:Label ID="lblNumeIntreg" runat="server" Text='<%# Bind("NumeIntreg") %>'></asp:Label>
                                
                                <telerik:RadCheckBox ID="chkInlocuire" runat="server" Text="Inlocuire" CommandName="Inlocuire" OnCheckedChanged="chkInlocuire_CheckedChanged">
                                </telerik:RadCheckBox>

                                <telerik:RadComboBox RenderMode="Lightweight" runat="server" visible="false" ID="RadComboBox1" EnableLoadOnDemand="True" DataTextField="NumeIntreg2"
                                    OnItemsRequested="RadComboBox1_ItemsRequested" DataValueField="ID_Profesor"
                                    HighlightTemplatedItems="true" Height="140px" Width="220px" DropDownWidth="420px"
                                    OnSelectedIndexChanged="OnSelectedIndexChangedHandler">
                                    <ItemTemplate>
                                                <%# DataBinder.Eval(Container, "Attributes['NumeIntreg']")%> -- / --
                                                <%# DataBinder.Eval(Container, "Attributes['DenumireCatedra']")%>
                                    </ItemTemplate>
                                </telerik:RadComboBox>

                            </ItemTemplate>
                        </telerik:GridTemplateColumn>

                        <telerik:GridBoundColumn DataField="ID_ProfesorTitularCurs" DataType="System.Int64" FilterControlAltText="Filter ID_ProfesorTitularCurs column" HeaderText="ID_ProfesorTitularCurs" SortExpression="ID_ProfesorTitularCurs" UniqueName="ID_ProfesorTitularCurs" visible="false">
                        </telerik:GridBoundColumn>

                        <telerik:GridTemplateColumn DataField="Data" DataType="System.DateTime" FilterControlAltText="Filter DataInceputPeSpec column" HeaderText="Data" SortExpression="Data" UniqueName="Data">
                            <ItemTemplate>
                                <telerik:RadDatetimePicker RenderMode="Lightweight" ID="rdpData" CssClass="toDate" runat="server" MinDate="2020-01-01" DbSelectedDate='<%# Bind("Data") %>' Culture="ro-RO"  width="180px" FocusedDate="2020-01-01">
                                    <timeview cellspacing="-1" culture="ro-RO" endtime="21:00:00" headertext="Ora" rendermode="Lightweight" starttime="07:00:00">
                                    </timeview>
                                    <ClientEvents OnDateSelected="OnDateSelected"></ClientEvents>
                                </telerik:RadDatetimePicker>
                                <asp:Label ID="lblAtentie" runat="server" Text=" "></asp:Label>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn DataField="Sala" FilterControlAltText="Filter Sala column" HeaderText="Sala" SortExpression="Sala" UniqueName="Sala">
                            <ItemTemplate>
                                <asp:TextBox ID="txtSala" runat="server" Text='<%# Bind("Sala") %>'></asp:TextBox>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn DataField="ID_TipExaminare" DataType="System.Int32" HeaderText="Tip Examinare" SortExpression="ID_TipExaminare" UniqueName="ID_TipExaminare">
                            <ItemTemplate>
                                <asp:DropDownList ID="ddTipExaminare" runat="server" SelectedValue='<%# Eval("ID_TipExaminare") %>'>
                                    <asp:ListItem Text="Scris" Value="1"></asp:ListItem>
                                    <asp:ListItem Text="Oral" Value="2"></asp:ListItem>
                                    <asp:ListItem Text="Practic" Value="3"></asp:ListItem>
                                </asp:DropDownList>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>

                        <telerik:GridTemplateColumn>
                            <ItemTemplate>
                                <telerik:radButton id="btnFinalizareFalse" runat="server" CommandName="FinalizareFalse" Text="Sterge Finalizare" UniqueName="FinalizareFalse" Resizable="false" OnClientClicking="onClientFinalizareFalse">
                                </telerik:radButton>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>

                        <telerik:GridTemplateColumn>
                            <ItemTemplate>
                                <telerik:radbutton id="btnDeleteColumn" runat="server" CommandName="Delete" Text="Sterge" UniqueName="DeleteColumn" Resizable="false" ConfirmText="Sterge programare?" OnClientClicking="onClientStergeProgramare">
                                </telerik:radbutton>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>

                    </Columns>
                    <groupbyexpressions>
                        <telerik:GridGroupByExpression>
                            <selectfields>
                                <telerik:GridGroupByField FieldAlias="DenumireCicluInv" FieldName="DenumireCicluInv" FormatString="" HeaderText="" />
                            </selectfields>
                            <groupbyfields>
                                <telerik:GridGroupByField FieldAlias="DenumireCicluInv" FieldName="DenumireCicluInv" FormatString="" HeaderText="" />
                            </groupbyfields>
                        </telerik:GridGroupByExpression>
                        <telerik:GridGroupByExpression>
                            <selectfields>
                                <telerik:GridGroupByField FieldAlias="DenumireFormaInv" FieldName="DenumireFormaInv" FormatString="" HeaderText="" />
                            </selectfields>
                            <groupbyfields>
                                <telerik:GridGroupByField FieldAlias="DenumireFormaInv" FieldName="DenumireFormaInv" FormatString="" HeaderText="" />
                            </groupbyfields>
                        </telerik:GridGroupByExpression>
                        <telerik:GridGroupByExpression>
                            <selectfields>
                                <telerik:GridGroupByField FieldAlias="DenumireSpecializare" FieldName="DenumireSpecializare" FormatString="" HeaderText="" />
                            </selectfields>
                            <groupbyfields>
                                <telerik:GridGroupByField FieldAlias="DenumireSpecializare" FieldName="DenumireSpecializare" FormatString="" HeaderText="" />
                            </groupbyfields>
                        </telerik:GridGroupByExpression>
                        <telerik:GridGroupByExpression>
                            <selectfields>
                                <telerik:GridGroupByField FieldAlias="DenumireAnStudiu" FieldName="DenumireAnStudiu" FormatString="" HeaderText="" />
                            </selectfields>
                            <groupbyfields>
                                <telerik:GridGroupByField FieldAlias="DenumireAnStudiu" FieldName="DenumireAnStudiu" FormatString="" HeaderText="" />
                            </groupbyfields>
                        </telerik:GridGroupByExpression>
                        <telerik:GridGroupByExpression>
                            <selectfields>
                                <telerik:GridGroupByField FieldAlias="DenumireGrupa" FieldName="DenumireGrupa" FormatString="" HeaderText="" />
                            </selectfields>
                            <groupbyfields>
                                <telerik:GridGroupByField FieldAlias="DenumireGrupa" FieldName="DenumireGrupa" FormatString="" HeaderText="" />
                            </groupbyfields>
                        </telerik:GridGroupByExpression>
                    </groupbyexpressions>
                </mastertableview>
            </telerik:RadGrid>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="xxxxxxxxxx" SelectCommand="PE.ProgramareExamenlListBySpecializareSesiuneExamene" SelectCommandType="StoredProcedure"  OnSelecting="SqlDataSource1_Selecting">
    <SelectParameters>
        <asp:Parameter Name="ID_AnUniv" Type="Int64" />
        <asp:Parameter Name="ID_Facultate" Type="Int64" />
        <asp:Parameter Name="ID_Specializare" Type="Int64" DefaultValue="-1" />
        <asp:Parameter Name="ID_AnStudiu" Type="Int64" DefaultValue="-1" />
        <asp:QueryStringParameter Name="ID_SesiuneExameneSpecializare" QueryStringField="ID_SesiuneExameneSpecializare" Type="Int64" DefaultValue="-1" />
    </SelectParameters>
</asp:SqlDataSource>

 

protected void gvProgramareExamene_ItemCommand(object sender, GridCommandEventArgs e)
        {
            GridDataItem item = e.Item as GridDataItem;

            // using DataKey
            object objID_ProgramareExamen = item.GetDataKeyValue("ID_ProgramareExamen");

            long ID_ProgramareExamen = objID_ProgramareExamen == DBNull.Value ? -1 : Convert.ToInt64(objID_ProgramareExamen);


            if (e.CommandName == "FinalizareFalse")
            {
                new ProgramareExamenProfesorController().ProgramareExamenUpdateNoteFinalizate(ID_ProgramareExamen, false);
            }
            else if (e.CommandName == "Delete")
            {
                if (ID_ProgramareExamen != -1)
                {
                    new ProgramareExamenProfesorController().ProgramareExamenDelete(ID_ProgramareExamen);
                }
            }

}

1 Answer, 1 is accepted

Sort by
0
Cata
Top achievements
Rank 1
answered on 02 Feb 2020, 08:20 AM

Found solution:

-https://www.telerik.com/forums/prevent-auto-rebinding-of-grid

That means that I had to change the CommandName from "Delete" to something else.

Tags
Grid
Asked by
Cata
Top achievements
Rank 1
Answers by
Cata
Top achievements
Rank 1
Share this question
or