Hi. I try get item from edit form template, when edit button pressed, to change some of their values.
But I always receive null.
My code:
gridDataItem.FindControl return null for all my ids.
Please help.
But I always receive null.
My code:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="True" DataSourceID="sqlDataFeedGrid" GridLines="Both" AllowPaging="True" AllowAutomaticUpdates="True" AllowAutomaticInserts="True" AllowAutomaticDeletes="True" OnInsertCommand="RadGrid1_InsertCommand" OnEditCommand="RadGrid1_EditCommand" OnPreRender="RadGrid1_PreRender" OnUpdateCommand="RadGrid1_UpdateCommand"> <PagerStyle Mode="NextPrevAndNumeric" /> <MasterTableView DataSourceID="sqlDataFeedGrid" AutoGenerateColumns="False" DataKeyNames="Id" CommandItemDisplay="Top"> <Columns> <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn" /> <telerik:GridBoundColumn DataField="Id" HeaderText="Datafeed ID" SortExpression="Id" UniqueName="Id" Visible="False" MaxLength="10" /> <telerik:GridBoundColumn DataField="IPAddress" DataType="System.String" HeaderText="IP Address" SortExpression="IPAddress" UniqueName="IPAddress" /> <telerik:GridBoundColumn DataField="Name" DataType="System.String" HeaderText="Name" SortExpression="Name" UniqueName="Name" /> <telerik:GridBoundColumn DataField="Status" DataType="System.String" HeaderText="Status" SortExpression="Status" UniqueName="Status" /> <telerik:GridBoundColumn DataField="Configs" DataType="System.Guid" HeaderText="Configs" SortExpression="Configs" UniqueName="Configs" /> <telerik:GridBoundColumn DataField="Logs" DataType="System.String" HeaderText="Logs" SortExpression="Logs" UniqueName="Logs" /> <telerik:GridBoundColumn DataField="setupInstruction" DataType="System.Guid" HeaderText="Install Instruction" SortExpression="setupInstruction" UniqueName="setupInstruction" /> <telerik:GridBoundColumn DataField="execInstruction" DataType="System.Guid" HeaderText="Execute Instruction" SortExpression="execInstruction" UniqueName="execInstruction" /> <telerik:GridBoundColumn DataField="Description" DataType="System.String" HeaderText="Description" SortExpression="Description" UniqueName="Description" /> <telerik:GridButtonColumn Text="Delete" CommandName="Delete" ButtonType="ImageButton" /> </Columns> <EditFormSettings EditFormType="Template"> <EditColumn UniqueName="EditColumn"></EditColumn> <FormTemplate> <table cellspacing="2" cellpadding="1" width="100%" border="0" rules="none" style="border-collapse: collapse;"> <tr class="EditFormHeader"> <td colspan="2" style="font-size: small"> <b>Datafeed Details</b> </td> </tr> <tr> <td></td> <td></td> </tr> <tr> <td>ID</td> <td> <asp:TextBox ID="txtId" runat="server" ValidationGroup="Datafeed" ReadOnly="true" Text='<%# Bind("Id") %>' /> </td> </tr> <tr> <td>IP Address </td> <td> <asp:DropDownList ID="ddlMachineId" EnableViewState="true" AutoPostBack="true" runat="server" DataSourceID="sqlMachineId" DataTextField="IPAddress" DataValueField="ID" OnSelectedIndexChanged="ddlMachineId_IndexChange" /> <asp:Label ID="lblHostingName" runat="server"></asp:Label> </td> </tr> <tr> <td>Data Agent</td> <td> <asp:DropDownList ID="ddlDataAgentID" runat="server" DataSourceID="sqlDataAgentId" DataTextField="Name" DataValueField="ID"> </asp:DropDownList><asp:Button ID="addAgent" runat="server" Text="Add" Width="55px" OnClick="addAgent_Click" /> <asp:ListBox ID="agentsList" runat="server" Height="91px" Width="194px"></asp:ListBox> </td> </tr> <tr> <td>Datafeed Name</td> <td> <asp:TextBox ID="txtName" runat="server" ValidationGroup="Datafeed" Text='<%# Bind("Name") %>' /> </td> </tr> <tr> <td>Status</td> <td> <asp:TextBox ID="txtStatus" runat="server" ValidationGroup="Datafeed" Text='<%# Bind("Status") %>'></asp:TextBox> </td> </tr> <tr> <td>Config File</td> <td> <asp:FileUpload runat="server" ID="configFile" Width="229px" /> <asp:HyperLink runat="server" ID="confResult" Target="_blank" /> </td> </tr> <tr> <td>Logs Path</td> <td> <asp:TextBox ID="txtLogs" runat="server" ValidationGroup="Datafeed" Text='<%# Bind("Logs") %>'></asp:TextBox> </td> </tr> <tr> <td>Install Instruction</td> <td> <asp:FileUpload runat="server" ID="setupFile" Width="229px" /> <asp:HyperLink runat="server" ID="setupResult" Target="_blank" /> </td> </tr> <tr> <td>Execute Instruction</td> <td> <asp:FileUpload runat="server" ID="execFile" Width="229px" /> <asp:HyperLink runat="server" ID="execResult" Target="_blank" /> </td> </tr> <tr> <td>Description</td> <td> <asp:TextBox ID="txtDescription" runat="server" ValidationGroup="Datafeed" TextMode="MultiLine" Height="58px" Width="303px" Text='<%# Bind("Description") %>'></asp:TextBox> </td> </tr> </table> <asp:Button runat="server" ID="btnUpdate" Text='<%#(Container is GridEditFormInsertItem) ? "Insert":"Update" %>' CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert":"Update" %>' /> <asp:Button runat="server" ID="btnCancel" Text="Cancel" CausesValidation="False" CommandName="Cancel" /> </FormTemplate> </EditFormSettings> </MasterTableView> <ClientSettings> <ClientEvents OnRowDblClick="RowDblClick"></ClientEvents> </ClientSettings></telerik:RadGrid>protected void RadGrid1_EditCommand(object sender, GridCommandEventArgs e) { if (e.CommandName != RadGrid.EditCommandName) return; GridDataItem gridDataItem = e.Item as GridDataItem; var ddlMachineId = gridDataItem.FindControl("ddlMachineId") as DropDownList; var ddlDataAgentID = gridDataItem.FindControl("ddlDataAgentID") as DropDownList; var agentsList = gridDataItem.FindControl("agentsList") as ListBox; var confResult = gridDataItem.FindControl("confResult") as HyperLink; var execResult = gridDataItem.FindControl("execResult") as HyperLink; var setupResult = gridDataItem.FindControl("setupResult") as HyperLink;}gridDataItem.FindControl return null for all my ids.
Please help.