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

[Solved] Get values from grid with custom form

17 Answers 391 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Iron
Iron
Iron
Daniel asked on 07 Jan 2010, 02:32 AM
Hi. I have a hierarchial grid with a custom insert form. The form is opened when a user clicks on an 'insert' link in the grid. These 'insert' links are found at the end of each row in selected grids in the hierarchy. How do I extract a value from the row that a user clicks the 'insert' on. I already know how to extract the primary key. Thanks.

Daniel

17 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 07 Jan 2010, 04:56 AM
Hello Daniel,

You can try out the following code to access a cell value when the Insert link is clicked for the same row:
c#:
protected void btnInsert_Click(object sender, EventArgs e) 
    { 
       LinkButton btnInsert = (LinkButton)sender; 
       GridDataItem dataItem = (GridDataItem)btnInsert.NamingContainer; 
       string text = dataItem["ColumnUniqueName"].Text; 
    } 

Thanks
Princy.
0
Daniel
Top achievements
Rank 1
Iron
Iron
Iron
answered on 07 Jan 2010, 05:50 AM
Thanks for the quick reply Princy. I should have explained a bit better. I need to get the value from the grid row when inside the custom edit form. The link button acts like a custom insert button. Thanks.

Daniel
0
Radoslav
Telerik team
answered on 07 Jan 2010, 04:25 PM
Hi Daniel,

In order to achieve your goal, you could try setting the insert button CommandName to "PerformInsesrt". Then when you use User Control Edit Form you could get the value from control into the UserControl with the following code snippet:

void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
   if (e.CommandName == "PerformInsert")
   {
      string value = (userControl.FindControl("TextBox1") as TextBox).Text;
   }
}

Also you could check the following online example which demonstrates custom edit form with UserControl:

http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/usercontroleditform/defaultcs.aspx

If you have default edit forms for editing, you could get the value with the following code:

void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
    if (e.CommandName == "PerformInsert")
    {
       GridEditFormInsertItem item = e.Item as GridEditFormInsertItem;
       TextBox tb = item.FindControl("TextBox1") as TextBox;
       string value = tb.Text;
    }
}

I hope this helps.

Sincerely yours,
Radoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Daniel
Top achievements
Rank 1
Iron
Iron
Iron
answered on 07 Jan 2010, 10:38 PM
Hi Radoslav. I need to get a value from the page that the grid is on (default.aspx) from my user control (usercontrol.ascx), not the other way around. Specifically, I need to grab a value from the row that my insert button is on. Thanks.

Daniel
0
Daniel
Top achievements
Rank 1
Iron
Iron
Iron
answered on 07 Jan 2010, 11:35 PM
Scratch that, I found a way around my problem. Thanks guys for your help.

Daniel
0
Daniel
Top achievements
Rank 1
Iron
Iron
Iron
answered on 08 Jan 2010, 06:03 AM
Hmmm, okay, not quite fixed yet. I can't post any code, it's a deep nested grid with too much code. See my little grid below:

+-----------------------------------------------------------+
| DEV        Available          10/10/2009        Book |
TRAIN     Not available    01/01/2010        Book |  <-- user clicks book, brings up custom form, user fills in form, clicks on insert
+-----------------------------------------------------------+

When the form closes and in code behind comes back to the OnInsertCommand, I need to extract the value TRAIN from the grid, or even if I could extract it from within the form, that would be okay. It is a hierarchical grid and the value TRAIN is a Literal control inside a GridTemplateColumn. Here is part of my code behind for the OnInsertCommand:

    protected void rgEnvironments_InsertCommand(object source, GridCommandEventArgs e)  
    {  
        GridEditableItem editedItem = e.Item as GridEditableItem;  
        UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);  
        string envID = null// Need to get TRAIN here
        string envModule = (userControl.FindControl("rcbModule"as RadComboBox).SelectedValue;  
        string envReason = (userControl.FindControl("rcbReason"as RadComboBox).SelectedValue;  
        string envDetails = (userControl.FindControl("rtbDetails"as RadTextBox).Text;  
        string envStartDate = (userControl.FindControl("rdpStart"as RadDatePicker).SelectedDate.Value.ToShortDateString();  
        envStartDate = envStartDate + " " + (userControl.FindControl("rtpStart"as RadTimePicker).SelectedDate.Value.ToShortTimeString();  
        string envCompletion = (userControl.FindControl("rdpCompletion"as RadDatePicker).SelectedDate.Value.ToShortDateString();  
        envCompletion = envCompletion + " " + (userControl.FindControl("rtpCompletion"as RadTimePicker).SelectedDate.Value.ToShortTimeString();  
        string envSupportRef = (userControl.FindControl("rntSupportRef"as RadNumericTextBox).Text;  
        try 
        {  
            myConnection = new SqlConnection(Intranet.ConString("/Default Web Site""IntranetConnectionString"));  
            myConnection.Open();  
            myCommand = new SqlCommand("InsertTeamImUsage", myConnection);  
            myCommand.CommandType = CommandType.StoredProcedure;  
            myCommand.Parameters.Add("@environment_id", SqlDbType.VarChar).Value = (object)envID ?? DBNull.Value;  
            myCommand.Parameters.Add("@user", SqlDbType.VarChar).Value = (object)Intranet.UserID() ?? DBNull.Value;  
            myCommand.Parameters.Add("@module_id", SqlDbType.Int).Value = (object)envModule ?? DBNull.Value;  
            myCommand.Parameters.Add("@reason_id", SqlDbType.Int).Value = (object)envReason ?? DBNull.Value;  
            myCommand.Parameters.Add("@details", SqlDbType.VarChar).Value = (object)envDetails ?? DBNull.Value;  
            myCommand.Parameters.Add("@start_date", SqlDbType.DateTime).Value = (object)envStartDate ?? DBNull.Value;  
            myCommand.Parameters.Add("@end_date", SqlDbType.DateTime).Value = (object)envCompletion ?? DBNull.Value;  
            myCommand.Parameters.Add("@support_ref", SqlDbType.Int).Value = (object)envSupportRef ?? DBNull.Value;  
            myCommand.ExecuteNonQuery();  
        }  
        catch (Exception ex)  
        {  
            Intranet.AppendLogFile(ex.Message + ex.StackTrace);  
            e.Canceled = true;  
        }  
        finally 
        {  
            myConnection.Close();  
        }  
    } 

0
Daniel
Top achievements
Rank 1
Iron
Iron
Iron
answered on 10 Jan 2010, 10:34 PM
No takers?
0
Radoslav
Telerik team
answered on 11 Jan 2010, 02:11 PM
Hi Daniel,

In order to achieve your goal you could try the following code snippet:

void RadGrid1_InsertCommand(object source, GridCommandEventArgs e)
{
   GridEditFormInsertItem item = e.Item as GridEditFormInsertItem;
   Literal literal = item["TemplateColumnUniqueName"].FindControl("LiteralID") as Literal;
}
With this code you could get the Literal control in the same DetailTables as you add/edit.

If your Literal control is in a parent DetailTables you could use the following sode:

void RadGrid1_InsertCommand(object source, GridCommandEventArgs e)
{
    GridEditFormInsertItem item = e.Item as GridEditFormInsertItem;
    Literal literal = (item.OwnerTableView.Parent.NamingContainer as GridNestedViewItem).ParentItem["ParentTemplateColumnUniqueName"].FindControl("LiteralID") as Literal;
}

I hope this helps.

Greetings,
Radoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Daniel
Top achievements
Rank 1
Iron
Iron
Iron
answered on 12 Jan 2010, 01:13 AM
Thanks for the reply Radoslav. I get the error below when the PerformInsert command is fired from my web control. Thanks.

    Item in insert mode does implement indexer only when the edit form is autogenerated

0
Daniel
Top achievements
Rank 1
Iron
Iron
Iron
answered on 13 Jan 2010, 04:41 AM
This really has me stuck, any ideas?

Daniel
0
Radoslav
Telerik team
answered on 13 Jan 2010, 11:12 AM
Hello Daniel,

Could you post the code from PerformInsert command? Is it the same as in your first post? Do you add one of the code snippets in my last post?
Additionally,  I'm guessing the error is because you need the following check in your code to avoid trying to assign a value when the form is not in INSERT mode:

<< if (e.Item is GridEditFormInsertItem) >>

However, It is hard to say what is causing this problem without seeing some code. Also you could you open a support ticket and provide a sample app that recreates this problem. We will check it and do our best to help.

Sincerely yours,
Radoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Daniel
Top achievements
Rank 1
Iron
Iron
Iron
answered on 13 Jan 2010, 10:42 PM
Hi Radoslav. I tried the check and it still failed with same error. Here is most of my code from both the RadGrid and custom form. Thanks for your time.

ASPX from RadGrid:

<%@ Page Title="Environments" Language="C#" MasterPageFile="~/masterpage.master" 
    AutoEventWireup="true" CodeFile="default.aspx.cs" Inherits="teams_im_environment_usage_default" %> 
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"
    <telerik:RadDockLayout ID="rdlMain" runat="server"
        <telerik:RadDockZone ID="rdzMain" runat="server"
            <telerik:RadDock ID="rdMain" runat="server" Title="Environments" DefaultCommands="ExpandCollapse" 
                DockMode="Docked" Skin="Simple" ForbiddenZones="rdzLeft,rdzRight"
                <ContentTemplate> 
                    <div class="dock_wrapper"
                        <telerik:RadGrid ID="rgEnvironments" Skin="Forest" runat="server" GridLines="None" 
                            DataSourceID="sdsSystems" OnColumnCreated="rgEnvironments_ColumnCreated" AllowAutomaticDeletes="True" 
                            AllowAutomaticUpdates="False" AllowAutomaticInserts="False" OnItemCommand="rgEnvironments_ItemCommand" 
                            OnInsertCommand="rgEnvironments_InsertCommand" OnItemDataBound="rgEnvironments_ItemDataBound"
                            <MasterTableView AutoGenerateColumns="False" DataKeyNames="system_id" DataSourceID="sdsSystems" 
                                Name="systems"
                                <HeaderStyle CssClass="team_im_systems_header" /> 
                                <ItemStyle CssClass="team_im_systems_row" /> 
                                <AlternatingItemStyle CssClass="team_im_systems_row" /> 
                                <DetailTables> 
                                    <telerik:GridTableView Name="environments" DataKeyNames="system_id, environment_id" 
                                        DataSourceID="sdsEnvironments" Width="100%" runat="server" AutoGenerateColumns="false" 
                                        ShowHeader="false" BorderStyle="None" GridLines="None" CssClass="team_im_users_expand"
                                        <ParentTableRelation> 
                                            <telerik:GridRelationFields DetailKeyField="system_id" MasterKeyField="system_id" /> 
                                        </ParentTableRelation> 
                                        <HeaderStyle CssClass="team_im_environments_header" /> 
                                        <ItemStyle CssClass="team_im_environments_row" /> 
                                        <AlternatingItemStyle CssClass="team_im_environments_row" /> 
                                        <DetailTables> 
                                            <telerik:GridTableView Name="users" DataKeyNames="usage_id" DataSourceID="sdsUsers" 
                                                Width="100%" runat="server" AutoGenerateColumns="false" BorderStyle="None" GridLines="None" 
                                                CssClass="team_im_users_row"
                                                <ParentTableRelation> 
                                                    <telerik:GridRelationFields DetailKeyField="environment_id" MasterKeyField="environment_id" /> 
                                                </ParentTableRelation> 
                                                <HeaderStyle CssClass="team_im_users_header" /> 
                                                <ItemStyle CssClass="team_im_users_row" /> 
                                                <AlternatingItemStyle CssClass="team_im_users_row" /> 
                                                <Columns> 
                                                    <telerik:GridHyperLinkColumn DataNavigateUrlFields="pkEmployeeNumber" SortExpression="fullname" 
                                                        UniqueName="fullname" Target="_blank" DataNavigateUrlFormatString="http://ha-intra01.council.herveybay.qld.gov.au/people/profiles/?empno={0}" 
                                                        HeaderText="User" DataTextField="fullname" DataType="System.String" HeaderStyle-Width="16%"
                                                    </telerik:GridHyperLinkColumn> 
                                                    <telerik:GridTemplateColumn HeaderText="environment_id" UniqueName="environment_id" 
                                                        Display="false"
                                                        <ItemTemplate> 
                                                            <asp:Literal ID="ltlEnvironmentID" Text='<%# Bind("environment_id") %>' runat="server" /></ItemTemplate
                                                    </telerik:GridTemplateColumn> 
                                                    <telerik:GridTemplateColumn HeaderText="Module" UniqueName="module" HeaderStyle-Width="16%"
                                                        <ItemTemplate> 
                                                            <asp:Literal ID="ltlModule" Text='<%# Bind("module") %>' runat="server" /></ItemTemplate
                                                    </telerik:GridTemplateColumn> 
                                                    <telerik:GridTemplateColumn HeaderText="module_id" UniqueName="module_id" Display="false"
                                                        <ItemTemplate> 
                                                            <asp:Literal ID="ltlModuleID" Text='<%# Bind("module_id") %>' runat="server" /></ItemTemplate
                                                    </telerik:GridTemplateColumn> 
                                                    <telerik:GridTemplateColumn HeaderText="Reason" UniqueName="reason" HeaderStyle-Width="16%"
                                                        <ItemTemplate> 
                                                            <asp:Literal ID="ltlReason" Text='<%# Bind("reason") %>' runat="server" /></ItemTemplate
                                                    </telerik:GridTemplateColumn> 
                                                    <telerik:GridTemplateColumn HeaderText="reason_id" UniqueName="reason_id" Display="false"
                                                        <ItemTemplate> 
                                                            <asp:Literal ID="ltlReasonID" Text='<%# Bind("reason_id") %>' runat="server" /></ItemTemplate
                                                    </telerik:GridTemplateColumn> 
                                                    <telerik:GridTemplateColumn HeaderText="Details" UniqueName="details" HeaderStyle-Width="16%"
                                                        <ItemTemplate> 
                                                            <asp:Literal ID="ltlDetails" Text='<%# Bind("details") %>' runat="server" /></ItemTemplate
                                                    </telerik:GridTemplateColumn> 
                                                    <telerik:GridTemplateColumn HeaderText="Completion" UniqueName="end_date" HeaderStyle-Width="16%"
                                                        <ItemTemplate> 
                                                            <asp:Literal ID="ltlEndDate" Text='<%# Bind("end_date") %>' runat="server" /></ItemTemplate
                                                    </telerik:GridTemplateColumn> 
                                                    <telerik:GridTemplateColumn UniqueName="support_ref" HeaderText="Support Ref" HeaderStyle-Width="16%"
                                                        <ItemTemplate> 
                                                            <asp:HyperLink ID="hlSupportRef" runat="server" NavigateUrl='<%# Bind("support_ref_url") %>' 
                                                                Text='<%# Bind("support_ref") %>' Target="_blank" /> 
                                                        </ItemTemplate> 
                                                    </telerik:GridTemplateColumn> 
                                                    <telerik:GridTemplateColumn UniqueName="UpdateUsage" HeaderStyle-Width="2%"
                                                        <ItemTemplate> 
                                                            <asp:LinkButton ID="lbUpdateUsage" Text="Update" CommandName="UpdateUsage" runat="server" /> 
                                                        </ItemTemplate> 
                                                    </telerik:GridTemplateColumn> 
                                                    <telerik:GridButtonColumn ConfirmText="Are you sure you want to close this item?" 
                                                        ConfirmDialogType="RadWindow" ConfirmTitle="Close" CommandName="Delete" Text="Close" 
                                                        UniqueName="DeleteColumn" HeaderStyle-Width="2%" ItemStyle-HorizontalAlign="Right"
                                                    </telerik:GridButtonColumn> 
                                                </Columns> 
                                            </telerik:GridTableView> 
                                        </DetailTables> 
                                        <Columns> 
                                            <telerik:GridTemplateColumn HeaderText="environment_id" UniqueName="environment_id" Display="false"
                                                <ItemTemplate> 
                                                    <asp:Literal ID="ltlEnvironmentID" Text='<%# Bind("environment_id") %>' runat="server" /></ItemTemplate
                                            </telerik:GridTemplateColumn> 
                                            <telerik:GridTemplateColumn HeaderText="System/Environment" UniqueName="environment" HeaderStyle-Width="24%"
                                                <ItemTemplate> 
                                                    <asp:Literal ID="ltlEnvironment" Text='<%# Bind("environment") %>' runat="server" /></ItemTemplate
                                            </telerik:GridTemplateColumn> 
                                            <telerik:GridTemplateColumn HeaderText="Status" UniqueName="status" HeaderStyle-Width="24%"
                                                <ItemTemplate> 
                                                    <asp:Literal ID="ltlStatus" Text='<%# Bind("status") %>' runat="server" /></ItemTemplate
                                            </telerik:GridTemplateColumn> 
                                            <telerik:GridTemplateColumn HeaderText="Last Update" UniqueName="last_refresh" HeaderStyle-Width="24%"
                                                <ItemTemplate> 
                                                    <asp:Literal ID="ltlLastUpdate" Text='<%# Bind("last_refresh") %>' runat="server" /></ItemTemplate
                                            </telerik:GridTemplateColumn> 
                                            <telerik:GridTemplateColumn UniqueName="ExpandCollapse" HeaderStyle-Width="23%"
                                                <ItemTemplate> 
                                                    <asp:Literal ID="ltlExpandUsers" runat="server" Text='<%# Bind("users") %>' Visible='<%#DataBinder.Eval(Container.DataItem,"users").ToString()=="0"?true:false%>' /> 
                                                    <asp:LinkButton ID="lbExpandUsers" Text='<%# Bind("users")%>' Visible='<%#DataBinder.Eval (Container.DataItem,"users").ToString()!="0"?true:false %>' 
                                                        runat="server" OnClick="lbExpandUsers_Click"></asp:LinkButton> 
                                                </ItemTemplate> 
                                            </telerik:GridTemplateColumn> 
                                            <telerik:GridTemplateColumn UniqueName="ExpandCollapse" HeaderStyle-Width="3%"
                                                <ItemTemplate> 
                                                    <asp:LinkButton ID="lbBook" Text="Book" CommandName="book" runat="server" /> 
                                                </ItemTemplate> 
                                            </telerik:GridTemplateColumn> 
                                            <telerik:GridTemplateColumn UniqueName="ExpandCollapse" HeaderStyle-Width="2%"
                                                <ItemTemplate> 
                                                    <asp:LinkButton ID="lbRefresh" Text="Refresh" runat="server" /> 
                                                </ItemTemplate> 
                                            </telerik:GridTemplateColumn> 
                                        </Columns> 
                                    </telerik:GridTableView> 
                                </DetailTables> 
                                <Columns> 
                                    <telerik:GridBoundColumn DataField="system" HeaderText="System/Environment" SortExpression="system" 
                                        UniqueName="system" HeaderStyle-Width="24%"
                                    </telerik:GridBoundColumn> 
                                    <telerik:GridBoundColumn HeaderText="Status" UniqueName="sys_status" DataField="<%=DisplayNull() %>" 
                                        HeaderStyle-Width="24%"
                                    </telerik:GridBoundColumn> 
                                    <telerik:GridBoundColumn HeaderText="Last Update" UniqueName="sys_last_update" DataField="<%=DisplayNull() %>" 
                                        HeaderStyle-Width="24%"
                                    </telerik:GridBoundColumn> 
                                    <telerik:GridBoundColumn HeaderText="Users" UniqueName="sys_users" DataField="<%=DisplayNull() %>" 
                                        HeaderStyle-Width="23%"
                                    </telerik:GridBoundColumn> 
                                    <telerik:GridBoundColumn HeaderText="Actions" UniqueName="sys_actions" DataField="<%=DisplayNull() %>" 
                                        HeaderStyle-Width="5%" HeaderStyle-HorizontalAlign="Right"
                                    </telerik:GridBoundColumn> 
                                </Columns> 
                            </MasterTableView> 
                        </telerik:RadGrid> 
                    </div> 
                </ContentTemplate> 
            </telerik:RadDock> 
        </telerik:RadDockZone> 
    </telerik:RadDockLayout> 
    <asp:SqlDataSource ID="sdsReasons" runat="server" ConnectionString="<%$ ConnectionStrings:IntranetConnectionString %>" 
        SelectCommand="SelectTeamImReasons" SelectCommandType="StoredProcedure"></asp:SqlDataSource> 
    <asp:SqlDataSource ID="sdsModules" runat="server" ConnectionString="<%$ ConnectionStrings:IntranetConnectionString %>" 
        SelectCommand="SelectTeamImModules2" SelectCommandType="StoredProcedure"></asp:SqlDataSource> 
    <asp:SqlDataSource ID="sdsSystems" runat="server" ConnectionString="<%$ ConnectionStrings:IntranetConnectionString %>" 
        SelectCommand="SelectTeamImEnvironmentsSystems" SelectCommandType="StoredProcedure"
    </asp:SqlDataSource> 
    <asp:SqlDataSource ID="sdsEnvironments" runat="server" ConnectionString="<%$ ConnectionStrings:IntranetConnectionString %>" 
        SelectCommand="SelectTeamImEnvironments" SelectCommandType="StoredProcedure"
        <SelectParameters> 
            <asp:Parameter Name="system_id" Type="Int32" /> 
        </SelectParameters> 
    </asp:SqlDataSource> 
    <asp:SqlDataSource ID="sdsUsers" runat="server" ConnectionString="<%$ ConnectionStrings:IntranetConnectionString %>" 
        SelectCommand="SelectTeamImUsage" SelectCommandType="StoredProcedure" DeleteCommand="DeleteTeamImUser" 
        DeleteCommandType="StoredProcedure"
        <SelectParameters> 
            <asp:Parameter Name="environment_id" Type="Int32" /> 
        </SelectParameters> 
        <DeleteParameters> 
            <asp:Parameter Name="usage_id" Type="Int32" /> 
        </DeleteParameters> 
    </asp:SqlDataSource> 
    <telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server"
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="rgEnvironments"
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="rgEnvironments" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManagerProxy> 
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Forest"
    </telerik:RadAjaxLoadingPanel> 
</asp:Content> 
 



ItemCommand & InsertCommand C# from RadGrid:
    protected void rgEnvironments_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        try 
        { 
            if (e.CommandName == "book"
            { 
                e.Canceled = true
                e.Item.OwnerTableView.EditFormSettings.EditFormType = GridEditFormType.WebUserControl; 
                e.Item.OwnerTableView.EditFormSettings.UserControlName = "/teams/im/environment_usage/insert_usage_form.ascx"
                e.Item.OwnerTableView.InsertItem(); 
            } 
        } 
        catch (Exception ex) 
        { 
            Intranet.AppendLogFile(ex.Message + ex.StackTrace); 
        } 
    } 
 
    protected void rgEnvironments_InsertCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.Item is GridEditFormInsertItem) 
        { 
            GridEditFormInsertItem item = e.Item as GridEditFormInsertItem; 
            Literal literal = item["environment_id"].FindControl("ltlEnvironmentID"as Literal; 
        } 
    } 

ASCX from CustomForm:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="insert_usage_form.ascx.cs" 
    Inherits="teams_im_environment_usage_insert_usage_form" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<table cellpadding="7" cellspacing="0" border="0" style="width: 100%"
    <tr> 
        <td style="font-weight: bold; width: 14%; background-color: #C6C6C6;"
            User 
        </td> 
        <td style="font-weight: bold; width: 14%; background-color: #C6C6C6;"
            Module 
        </td> 
        <td style="font-weight: bold; width: 14%; background-color: #C6C6C6;"
            Reason 
        </td> 
        <td style="font-weight: bold; width: 14%; background-color: #C6C6C6;"
            Details 
        </td> 
        <td style="font-weight: bold; width: 14%; background-color: #C6C6C6;"
            Start 
        </td> 
        <td style="font-weight: bold; width: 14%; background-color: #C6C6C6;"
            Completion 
        </td> 
        <td style="font-weight: bold; width: 14%; background-color: #C6C6C6;"
            Support Ref 
        </td> 
        <td style="font-weight: bold; width: 1%; background-color: #C6C6C6;"
        </td> 
        <td style="font-weight: bold; width: 1%; background-color: #C6C6C6;"
        </td> 
    </tr> 
    <tr> 
        <td style="background-color: #F0F0F0;"
            <asp:Literal ID="ltlUser" runat="server" /> 
        </td> 
        <td style="background-color: #F0F0F0;"
            <telerik:RadComboBox ID="rcbModule" runat="server" Skin="Default"
            </telerik:RadComboBox> 
        </td> 
        <td style="background-color: #F0F0F0;"
            <telerik:RadComboBox ID="rcbReason" DataSourceID="sdsReasons" DataTextField="reason" 
                DataValueField="reason_id" runat="server" Skin="Default"
            </telerik:RadComboBox> 
        </td> 
        <td style="background-color: #F0F0F0;"
            <telerik:RadTextBox ID="rtbDetails" runat="server" Skin="Default" /> 
        </td> 
        <td style="background-color: #F0F0F0;"
            <telerik:RadDatePicker ID="rdpStart" runat="server" Skin="Default"
            </telerik:RadDatePicker> 
            <asp:RequiredFieldValidator ID="rfvStartDate" runat="server" ErrorMessage="Start date cannot be empty" 
                Text="" Display="None" ControlToValidate="rdpStart"></asp:RequiredFieldValidator><asp:CompareValidator 
                    ID="cvStartDate" runat="server" ErrorMessage="Start date must occur before completion date" 
                    ControlToValidate="rdpStart" ControlToCompare="rdpCompletion" Operator="LessThanEqual" 
                    Text="" Display="None"></asp:CompareValidator> 
            <br /> 
            <telerik:RadTimePicker ID="rtpStart" runat="server" Skin="Default"
            </telerik:RadTimePicker> 
            <asp:RequiredFieldValidator ID="rfvStartTime" runat="server" ErrorMessage="Start time cannot be empty" 
                Text="" Display="None" ControlToValidate="rtpStart"></asp:RequiredFieldValidator><asp:CustomValidator 
                    ID="CustomValidator1" runat="server" OnServerValidate="cuvStartTime_ServerValidate" ControlToValidate="rtpStart" ErrorMessage="CustomValidator"></asp:CustomValidator> 
        </td> 
        <td style="background-color: #F0F0F0;"
            <telerik:RadDatePicker ID="rdpCompletion" runat="server" Skin="Default"
            </telerik:RadDatePicker> 
            <asp:RequiredFieldValidator ID="rfvCompletionDate" runat="server" ErrorMessage="Completion date cannot be empty" 
                Text="" Display="None" ControlToValidate="rdpCompletion"></asp:RequiredFieldValidator> 
            <br /> 
            <telerik:RadTimePicker ID="rtpCompletion" runat="server" Skin="Default"
            </telerik:RadTimePicker> 
            <asp:RequiredFieldValidator ID="rvfCompletionTime" runat="server" ErrorMessage="Completion time cannot be empty" 
                Text="" Display="None" ControlToValidate="rtpCompletion"></asp:RequiredFieldValidator> 
        </td> 
        <td style="background-color: #F0F0F0;"
            <telerik:RadNumericTextBox ID="rntSupportRef" runat="server" Skin="Default" NumberFormat-DecimalDigits="0" 
                NumberFormat-GroupSeparator=""
            </telerik:RadNumericTextBox> 
        </td> 
        <td style="background-color: #F0F0F0;"
            <asp:LinkButton ID="lbSave" runat="server" CommandName="PerformInsert" Style="color: #006ca2;">Save</asp:LinkButton> 
        </td> 
        <td style="background-color: #F0F0F0;"
            <asp:LinkButton ID="lbCancel" runat="server" CausesValidation="false" CommandName="Cancel" 
                Style="color: #006ca2;">Cancel</asp:LinkButton> 
        </td> 
    </tr> 
</table> 
<asp:ValidationSummary ID="ValidationSummary1" HeaderText="The following items need your attention:" 
    DisplayMode="BulletList" EnableClientScript="true" runat="server" /> 
 




C# from CustomForm:
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Data.SqlClient; 
using System.Data; 
using Telerik.Web.UI; 
using Common; 
 
public partial class teams_im_environment_usage_insert_usage_form : System.Web.UI.UserControl 
    SqlConnection myConnection; 
    SqlCommand myCommand; 
    SqlDataReader myReader; 
 
    protected void Page_Load(object sender, EventArgs e) 
    { 
        PopulateForm(); 
    } 
 
    void PopulateForm() 
    { 
        try 
        { 
            myConnection = new SqlConnection(Intranet.ConString("/Default Web Site""IntranetConnectionString")); 
            myConnection.Open(); 
 
            // User's name 
            myCommand = new SqlCommand("SelectFullname", myConnection); 
            myCommand.CommandType = CommandType.StoredProcedure; 
            myCommand.Parameters.Add("@userid", SqlDbType.VarChar).Value = (object)Intranet.UserID() ?? DBNull.Value; 
            myReader = myCommand.ExecuteReader(); 
            while (myReader.Read()) 
                ltlUser.Text = myReader["fullname"].ToString(); 
            myReader.Close(); 
 
            // Modules 
            // Grab primary key from parent grid on main page 
            GridEditableItem editedItem = (GridEditableItem)this.Parent.NamingContainer; 
            GridDataItem parentItem = (GridDataItem)editedItem.OwnerTableView.ParentItem; 
            int sysID = Intranet.Str2Int(parentItem.GetDataKeyValue("system_id").ToString()); 
 
            myCommand = new SqlCommand("SelectTeamImModules", myConnection); 
            myCommand.CommandType = CommandType.StoredProcedure; 
            myCommand.Parameters.Add("@system_id", SqlDbType.Int).Value = (object)sysID ?? DBNull.Value; 
            myReader = myCommand.ExecuteReader(); 
            while (myReader.Read()) 
                rcbModule.Items.Add(new RadComboBoxItem(myReader["module"].ToString(), myReader["module_id"].ToString())); 
            myReader.Close(); 
        } 
        catch (Exception ex) 
        { 
            Intranet.AppendLogFile(ex.Message + ex.StackTrace); 
        } 
        finally 
        { 
            myConnection.Close(); 
        } 
    } 

0
Daniel
Top achievements
Rank 1
Iron
Iron
Iron
answered on 17 Jan 2010, 11:40 PM
Radoslav, have you made any progress with this? It seems like a common thing to know what row you are inserting from which is basically what I'm trying to do. Thanks.

Daniel
0
Radoslav
Telerik team
answered on 19 Jan 2010, 07:29 AM
Hi Daniel,

I looked through your code and I think that the problem is caused by a few lines in the  rgEnvironments_InsertCommand event handler. Because the problematic RadGrid is hierarchical the environment_id is column only in the parent item and the following code throws an exception when the command is fired by item in the detail tables:
item["environment_id"].FindControl("ltlEnvironmentID") as Literal;

If you want to get value of Literal control which keeps the ID in hierarchical grid you could try the following code:
string parentID = ((GridNestedViewItem)(e.Item.OwnerTableView.NamingContainer)).ParentItem.GetDataKeyValue("environment_id").ToString();

Additionally I am attaching a simple example based on your code. I hope this helps.

All the best,
Radoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Daniel
Top achievements
Rank 1
Iron
Iron
Iron
answered on 20 Jan 2010, 04:58 AM
Thanks for the example Radoslav. I can get it to work okay but in my project, the InsertCommand keeps catching "Object reference not set to an instance of an object". I think I will try my project without using RadGrids. I appreciate your time and effort.

Daniel
0
Radoslav
Telerik team
answered on 22 Jan 2010, 04:04 PM
Hello Daniel,

It is hard to say what is causing this problem without being able to debug or at least check your code. Could you please open a support ticket and provide a sample application which recreates the described problem?
I understand that your project is large and complex, however you could send us a small piece of it. Replicating the issue in a simple project is not so hard as it looks and will help in isolating the problem. Or you could send us at least the page files (aspx, cs) so we could check your setup and thus try performing further investigation on it.
If you have worries about sending us the database you could try creating a small database which contains only several tables from the real one. If we have the project we will check it and do our best to help.

Greetings,
Radoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Daniel
Top achievements
Rank 1
Iron
Iron
Iron
answered on 25 Jan 2010, 01:50 AM
Thanks Radoslav. I will try a different approach.

Daniel
Tags
Grid
Asked by
Daniel
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Princy
Top achievements
Rank 2
Daniel
Top achievements
Rank 1
Iron
Iron
Iron
Radoslav
Telerik team
Share this question
or