how do i put some data on a detailedview on a nested grid through c#

14 posts, 1 answers
  1. DragonBall
    DragonBall avatar
    53 posts
    Member since:
    Jul 2008

    Posted 02 Aug 2008 Link to this post

    i pass the value of the dataset(ds) to the detailsview datasource but it wont work can anybody help me?

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="MeetingNotes.ascx.cs" Inherits="Project_MeetingNotes" %>

    <%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:MeetWebStyleConnectionString %>"
    SelectCommand="MWS_Meetings_Get_List" SelectCommandType="StoredProcedure">
    </asp:SqlDataSource>


    <asp:SqlDataSource ID="SqlDSBrainStormIDView" runat="server"
    ConnectionString="<%$ ConnectionStrings:MeetWebStyleConnectionString %>"
    SelectCommand="MWS_Brainstorm_items_GetByMeeting_idView"
    SelectCommandType="StoredProcedure" >
    <SelectParameters>
    <asp:ControlParameter ControlID="RadGrid1" DefaultValue="7" Name="Meeting_id"
    PropertyName="SelectedValue" Type="Int32" />
    <%--<asp:ControlParameter ControlID="Label1" PropertyName="Text" Type="String" Name="meeting_id" />--%>
    </SelectParameters>



    </asp:SqlDataSource>


    <telerik:RadScriptManager ID="RadScriptManager1" Runat="server">
    </telerik:RadScriptManager>


    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
    <telerik:AjaxSetting AjaxControlID="RadGrid1">
    <UpdatedControls>
    <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
    </UpdatedControls>
    </telerik:AjaxSetting>
    </AjaxSettings>
    </telerik:RadAjaxManager>

    <asp:Label ID="Label3" Font-Bold="true" Font-Italic="true" Text='<%# Eval("meetings_id") %>' Visible="false" runat="server" />
    <asp:Label ID="Label4" Font-Bold="true" Font-Italic="true" Text='<%# Eval("meetings_id") %>' Visible="false" runat="server" />
    <telerik:RadGrid ID="RadGrid1" runat="server"
    DataSourceID="SqlDataSource1"
    GridLines="None" AllowPaging="True" AutoGenerateColumns="False"
    Skin="Office2007" AllowFilteringByColumn="True" ItemStyle-Wrap="true" ItemStyle-Width="50px">


    <MasterTableView commanditemdisplay="Top" datasourceid="SqlDataSource1"
    editmode="PopUp" AllowPaging="true" AutoGenerateColumns="False"
    Font-Bold="False" Font-Italic="False" Font-Overline="False"
    Font-Strikeout="False" Font-Underline="False" width="100%" TableLayout="Fixed">

    <Columns>

    <telerik:GridBoundColumn DataField="meetings_id" HeaderText="Meeting ID"
    UniqueName="column" >
    <ItemStyle Width="50px" />
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn DataField="project_id" HeaderText="Project ID"
    UniqueName="column1" >
    <ItemStyle Width="50px" />
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn DataField="meeting_title" HeaderText="Title"
    UniqueName="column2" >
    <ItemStyle Width="50px" />
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn DataField="start_date" HeaderText="Starting Date"
    UniqueName="column3" >
    <ItemStyle Width="50px" />
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn DataField="end_date" HeaderText="End Date"
    UniqueName="column4" >
    <ItemStyle Width="50px" />
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn DataField="meeting_speaker_id" HeaderText="Speaker"
    UniqueName="column5">
    <ItemStyle Width="50px" />
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn DataField="recurrenceRule" HeaderText="Rule"
    UniqueName="column6" ItemStyle-Wrap="true" >
    <ItemStyle Wrap="true" Width="25px" />
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn DataField="recurrenceParentID" HeaderText="Rule ID"
    UniqueName="column7" >
    <ItemStyle Width="50px" />
    </telerik:GridBoundColumn>
    </Columns>
    <NestedViewTemplate>




    <asp:Label ID="Label1" Font-Bold="true" Font-Italic="true" Text='<%# Eval("meetings_id") %>' Visible="false" runat="server" />


    <asp:SqlDataSource ID="SqlDSMeetingNotes" runat="server"
    ConnectionString="<%$ ConnectionStrings:MeetWebStyleConnectionString %>"
    SelectCommand="MWS_Meeting_notes_GetByMeeting_id"
    SelectCommandType="StoredProcedure"
    InsertCommandType="StoredProcedure" InsertCommand="MWS_Meeting_notes_Insert"
    UpdateCommandType="StoredProcedure" UpdateCommand="MWS_Meeting_notes_Update">

    <SelectParameters>
    <asp:ControlParameter ControlID="Label1" PropertyName="Text" Type="String" Name="meeting_id" />
    </SelectParameters>
    <UpdateParameters>
    <asp:ControlParameter ControlID="Label1" PropertyName="Text" Type="String" Name="meeting_id" />
    </UpdateParameters>
    <InsertParameters>
    <asp:ControlParameter ControlID="Label1" PropertyName="Text" Type="String" Name="meeting_id" />
    </InsertParameters>

    </asp:SqlDataSource>


    <telerik:RadGrid ID="RAD1" runat="server" GridLines="None" AllowFilteringByColumn="True"
    AllowPaging="True" PageSize="5" AllowSorting="True" Width="100%" AutoGenerateColumns="False"
    ShowStatusBar="False" AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
    AllowAutomaticUpdates="True" DataSourceID="SqlDSMeetingNotes" HorizontalAlign="NotSet" Skin="Office2007" >


    <MasterTableView EditMode="PopUp" CommandItemDisplay="Top" DataKeyNames="meeting_id" AllowAutomaticInserts="True"
    AllowAutomaticUpdates="True" EditFormSettings-PopUpSettings-Width="800px" DataSourceID="SqlDSMeetingNotes">
    <GroupHeaderItemStyle />

    <Columns>
    <telerik:GridEditCommandColumn UniqueName="EditColumn" HeaderText="Meeting Note"/>
    <telerik:GridHTMLEditorColumn
    UniqueName="meeting_note_text"
    DataField="meeting_note_text"
    HeaderText="Notes" EditFormColumnIndex="1" />
    <telerik:GridDropDownColumn DataField="meeting_note_id"
    UniqueName="meeting_note_id"
    ListTextField="meeting_note_id"
    DataSourceID="SqlDSMeetingNotes"
    HeaderText="ID"
    DropDownControlType="RadComboBox" Resizable="true" EditFormColumnIndex="0" />
    <telerik:GridDropDownColumn DataField="user_id"
    UniqueName="user_id"
    ListTextField="user_id"
    DataSourceID="SqlDSMeetingNotes"
    HeaderText="USER ID"
    Display="false"
    DropDownControlType="RadComboBox" Resizable="true" EditFormColumnIndex="0" />
    </Columns>
    <EditFormSettings ColumnNumber="3" CaptionFormatString="Edit Meeting Details with Meeting {0}" CaptionDataField="meeting_id" >

    <FormTemplate>

    <table style="width: 171px">
    <tbody>
    <tr>
    <td>
    <asp:TextBox ID="TextBox2" runat="server"
    Text='<%# Bind("meeting_note_id") %>'></asp:TextBox>

    </td>
    <td>
    <asp:TextBox ID="TextBox1" runat="server"
    Text='<%# Bind("meeting_note_text") %>'></asp:TextBox>

    </td>
    </tr>
    <tr>
    <td>
    <asp:TextBox ID="TextBox3" runat="server"
    Text='<%# Bind("user_id") %>'></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td align="right" colspan="2">
    <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
    runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
    </asp:Button>&nbsp;
    <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
    CommandName="Cancel"></asp:Button></td>
    </tr>
    </tbody>
    </table>



    </FormTemplate>
    </EditFormSettings>

    </MasterTableView>
    </telerik:RadGrid>


    <asp:Label ID="Label2" Font-Bold="true" Font-Italic="true" Text='<%# Eval("project_id") %>' Visible="false" runat="server" />
    <asp:SqlDataSource ID="SqlDataSource2" runat="server"
    ConnectionString="<%$ ConnectionStrings:MeetWebStyleConnectionString %>"
    SelectCommand="MWS_Library_documentsView_GetByProjectID"
    SelectCommandType="StoredProcedure">
    <SelectParameters>
    <asp:ControlParameter ControlID="Label2" Name="project_id" PropertyName="Text"/>
    </SelectParameters>
    </asp:SqlDataSource>
    <telerik:RadGrid ID="RadGrid2" runat="server" GridLines="None" AllowFilteringByColumn="True"
    AllowPaging="True" PageSize="5" AllowSorting="True" Width="100%" AutoGenerateColumns="false"
    ShowStatusBar="False" AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
    AllowAutomaticUpdates="True" DataSourceID="SqlDataSource2" HorizontalAlign="NotSet" Skin="Office2007" OnPreRender="RadGrid2_PreRender"
    OnItemCommand ="Radgrid2_ItemCommand">
    <ClientSettings>
    <Selecting AllowRowSelect="True" />
    </ClientSettings>

    <MasterTableView EditMode="PopUp" CommandItemDisplay="Top" DataKeyNames="project_id" AllowAutomaticInserts="True"
    AllowAutomaticUpdates="True" EditFormSettings-PopUpSettings-Width="800px" >
    <GroupHeaderItemStyle />

    <Columns>
    <telerik:GridEditCommandColumn UniqueName="EditColumn1" HeaderText="Document"/>


    <telerik:GridBoundColumn
    DataField="thumbnail_available"
    UniqueName="thumbnail_available"
    EditFormColumnIndex="0"
    HeaderText="Thumbnail" Visible="false"
    />

    <telerik:GridBoundColumn
    DataField="library_docuemnt_images_id"
    UniqueName="library_docuemnt_images_id"
    EditFormColumnIndex="0"
    HeaderText="Library ID" Visible="false"
    />


    </Columns>
    <EditFormSettings ColumnNumber="3" CaptionFormatString="Edit Library Document {0}" CaptionDataField="meeting_id" >


    </EditFormSettings>
    <NestedViewTemplate>
    <fieldset style="padding:10px; azimuth:center; size:landscape; width:50%;">
    <legend style="padding:5px;"><b>Library:</b>
    <asp:Label ID="Label2" Font-Bold="true" Font-Italic="true" Text='<%# Eval("library_category_id") %>' Visible="false" runat="server" />

    </legend>

    <asp:SqlDataSource ID="SqlDataSource2" runat="server"
    ConnectionString="<%$ ConnectionStrings:MeetWebStyleConnectionString %>"
    SelectCommand="MWS_Library_documentsView_GetByProjectID"
    SelectCommandType="StoredProcedure">
    <SelectParameters>
    <asp:ControlParameter ControlID="Label2" Name="project_id" PropertyName="Text"/>
    </SelectParameters>
    </asp:SqlDataSource>


    <asp:DetailsView ID="DetailsView1" AllowPaging="true" GridLines="None" Width="100%" DataSourceID="SqlDataSource2"
    DataKeyNames="project_id" runat="server" CommandRowStyle-Wrap="false" AutoGenerateRows="false">

    <%--<Fields>
    <asp:BoundField
    DataField="library_category_id"
    HeaderText="ID"
    />
    </Fields>
    <Fields>
    <asp:BoundField
    DataField="iibrary_category_name"
    HeaderText="Name"
    />
    </Fields>
    <Fields>
    <asp:BoundField
    DataField="upload_date"
    HeaderText="Date"
    />
    </Fields>
    <Fields>
    <asp:BoundField
    DataField="uri"
    HeaderText="Location"
    />
    </Fields>
    <Fields>
    <asp:imagefield dataimageurlfield="uri"
    alternatetext="Image"
    nulldisplaytext="No image on file."
    headertext="Image"
    readonly="true"/>
    </Fields>--%>






    </asp:DetailsView>
    </fieldset>
    </NestedViewTemplate>
    </MasterTableView>
    </telerik:RadGrid>
    </NestedViewTemplate>







    <RowIndicatorColumn Visible="False"><HeaderStyle Width="20px"></HeaderStyle>
    </RowIndicatorColumn>

    <ExpandCollapseColumn Resizable="False">
    <HeaderStyle Width="20px"></HeaderStyle>
    </ExpandCollapseColumn>
    <Columns>

    <telerik:GridEditCommandColumn UniqueName="EditColumns" />

    </Columns>
    <EditFormSettings>

    <PopUpSettings ScrollBars="None"></PopUpSettings>
    </EditFormSettings>
    <GroupHeaderItemStyle Font-Bold="False" Font-Italic="False"
    Font-Overline="False" Font-Strikeout="False" Font-Underline="False"
    ForeColor="Black" Wrap="True" />

    <HeaderStyle BackColor="Black" Font-Bold="False" Font-Italic="False"
    Font-Overline="False" Font-Strikeout="False" Font-Underline="False"
    ForeColor="Black" Wrap="True" />
    </MasterTableView>
    <HeaderStyle ForeColor="Brown" />



    </telerik:RadGrid>


    <p>
    &nbsp;</p>

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using Telerik.Web.UI;
    public partial class Project_MeetingNotes : System.Web.UI.UserControl
    {
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Radgrid2_ItemCommand(object sender, EventArgs e)
    {

    Boolean strtxt;
    int documentid;
    foreach (GridNestedViewItem item1 in RadGrid1.MasterTableView.GetItems(GridItemType.NestedView))
    {
    RadGrid Grid2 = (RadGrid)item1.FindControl("RadGrid2");


    foreach (GridDataItem childitem in Grid2.MasterTableView.Items)
    {
    if (childitem.Selected)
    {

    strtxt = Convert.ToBoolean(childitem["thumbnail_available"].Text);

    if (strtxt != false)
    {
    documentid = Convert.ToInt32(childitem["library_docuemnt_images_id"].Text);
    DataSet ds = LibraryDocument.GetDocument(documentid);

    foreach (DataRow row in ds.Tables["Document"].Rows)
    {

    string documentImageId = string.Format("{0}", row["library_docuemnt_images_id"]);
    string libraryDocumentId = string.Format("{0}", row["library_document_id"]);
    string Uri = string.Format("{0}", row["uri"]);
    DetailsView dv =(DetailsView) Grid2.FindControl("DetailsView1");
    dv.DataSource = ds;


    }

    }
    }

    }

    }




    }






  2. Kiara
    Kiara avatar
    309 posts
    Member since:
    Jul 2006

    Posted 05 Aug 2008 Link to this post

    I took a look at your code and saw that you use stored procedure with name MWS_Library_documentsView_GetByProjectID to generate the data for the DetailsView control inside the NestedViewTemplate. Hence check whether this stored procedure has WHERE clause which referenced the defined select argument properly:

    <SelectParameters>
    <asp:ControlParameter ControlID="Label2" Name="project_id" PropertyName="Text"/>

    something like the following inside the stored procedure:

    SELECT .... WHERE ProjectID = @project_id

    Kiara

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. DragonBall
    DragonBall avatar
    53 posts
    Member since:
    Jul 2008

    Posted 05 Aug 2008 Link to this post

    there is a where Kiara and it actually need this code

    <asp:Label ID="Label2" Font-Bold="true" Font-Italic="true" Text='<%# Eval("project_id") %>' Visible="false" runat="server" />

  5. DragonBall
    DragonBall avatar
    53 posts
    Member since:
    Jul 2008

    Posted 05 Aug 2008 Link to this post

    is this the right way to call and store a datasource to detailsview from a nestedviewtemplate

    foreach (GridNestedViewItem item1 in RadGrid1.MasterTableView.GetItems(GridItemType.NestedView))
    {
    RadGrid Grid2 = (RadGrid)item1.FindControl("RadGrid2");

    DetailsView dv =(DetailsView) Grid2.FindControl("DetailsView1");
    dv.DataSource = ds;
    }

  6. Kiara
    Kiara avatar
    309 posts
    Member since:
    Jul 2006

    Posted 05 Aug 2008 Link to this post

    You missed the call to the DataBind() method of the DetailsView:

    foreach (GridNestedViewItem item1 in RadGrid1.MasterTableView.GetItems(GridItemType.NestedView))
    {
    RadGrid Grid2 = (RadGrid)item1.FindControl("RadGrid2");

    DetailsView dv =(DetailsView) Grid2.FindControl("DetailsView1");
    dv.DataSource = ds;
    dv.DataBind();
    }

    Kiara

  7. DragonBall
    DragonBall avatar
    53 posts
    Member since:
    Jul 2008

    Posted 05 Aug 2008 Link to this post

    it returns a null where you search for the control(detailviews1) it doesnt return a value, there is something wrong with my calling of the detailsview. can anybody help me with this.

    detailsview dv=(detailsview)grid2.findcontrol("detailsview1");

  8. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 05 Aug 2008 Link to this post

    Hello Manuel,

    You can go through the following code to access the DetailsView in the NestedViewTemplate of  RadGrid2 which is inturn in the NestedViewTemplate of RadGrid1.

    cs:
     protected void RadGrid1_PreRender(object sender, EventArgs e) 
        {                    
              foreach (GridNestedViewItem item1 in RadGrid1.MasterTableView.GetItems(GridItemType.NestedView)) 
                    { 
                        RadGrid Grid2 = (RadGrid)item1.FindControl("RadGrid2"); 
                        DetailsView dv = (DetailsView)Grid2.FindControl("DetailsView1"); 
                        foreach (GridNestedViewItem item2 in Grid2.MasterTableView.GetItems(GridItemType.NestedView)) 
                        { 
                            DetailsView dv = (DetailsView)item2.FindControl("DetailsView1"); 
                        } 
                    } 
        } 
     

    Thanks
    Princy.
  9. DragonBall
    DragonBall avatar
    53 posts
    Member since:
    Jul 2008

    Posted 05 Aug 2008 Link to this post

    Thank you very much Princy. it works perfectly
  10. DragonBall
    DragonBall avatar
    53 posts
    Member since:
    Jul 2008

    Posted 05 Aug 2008 Link to this post

    Princy i have another question because i have this code inside the heirarchy that you gave me, i need to put the dataset(ds) to an external control radgrid(RadGrid3) that is outside the heirarchy i try to put the code but it didnt work

    documentid = Convert.ToInt32(childitem["library_docuemnt_images_id"].Text);
    DataSet ds = LibraryDocument.GetDocument(documentid);

    RadGrid3.Datasource=ds;

    RadGrid3.Databind();

    but it doesnt work? how come the detailview works? thanx again princy

  11. John John
    John John avatar
    132 posts
    Member since:
    Aug 2009

    Posted 03 Nov 2009 Link to this post

    Hi..
               I would like to know how to bind the data to the grid, which is inside the NestedView template. I use to call NeedDatasource event for the corresponding Nested grid to bind the data. But is not firing or working properly. Is there any way to bind the data inside the Nested Grid

    -Thanks
  12. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 03 Nov 2009 Link to this post

    Hi John,

    This demo illustrates how to operate with nested view templates and embedded grids:
    http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/nestedviewtemplate/defaultcs.aspx

    If you want to use advanced binding with NeedDataSource event handling, configure the inner grid to bind in this way instead of using a data source control.

    Best regards,
    Sebastian
    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.
  13. John John
    John John avatar
    132 posts
    Member since:
    Aug 2009

    Posted 03 Nov 2009 Link to this post

    Hi Sebastian 
                                    Thanks for ur response, i readout the nestedview template demo, but i am facinf the problem in binding the grid which is under NestedViewTemplate dynamically. I just would like to know which event helps to bind the nested grid.


    -Thanks
  14. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 03 Nov 2009 Link to this post

    Hello John,

    Try intercepting the ItemDataBound event of the grid for this purpose and locate the nested grid by its id with the FindControl(gridId) executed for the e.Item argument in the handler.

    Best regards,
    Sebastian
    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.
  15. John John
    John John avatar
    132 posts
    Member since:
    Aug 2009

    Posted 04 Nov 2009 Link to this post

    Hi  Sebastian,
            Thanks for your comment, here i used RadGrid1_preRender event to bind the NestedView grid. It is working perfectly, but i am facing one issue. I have detail table section for the same nested view grid, when i try to view the detail table by expandaing nested grid the result is not coming. I am not able expand the nested grid,i hope the reason is when each time i am trying to expand grid as much time it calls the RadGrid1_preRender event so  as a result of these it binds the nested grid again and i am not able to view the detail table section.

    Please give me a solution to find the answer.

    -Thanks
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017