0

i have a datalist that displays the titles of events.When i click a title i want to display the event details like date,venue,description... outside the datalist
this is my code:

<asp:DataList ID="dlEvents" runat="server" HorizontalAlign="Left" GridLines="Both"
                        OnSelectedIndexChanged="SelectedIndexChanged">
                        <HeaderTemplate>
                            Events
                        </HeaderTemplate>
                        <HeaderStyle Font-Bold="true" Font-Size="16px" />
                        <ItemTemplate>
                            <table onmouseover="dg_changeBackColor(this, true);" onmouseout="dg_changeBackColor(this, false);">
                                <tr>
                                    <td>
                                        <%--  <asp:Label ID="lblEvntId" runat="server" Text='<%# Bind("prison_event_id") %>' Visible="false"></asp:Label>--%>
                                        <asp:Label ID="lblEvntTitle" runat="server" Text='<%# Bind("prison_event_title") %>'></asp:Label>
                                        <asp:Label ID="lblEvntId" runat="server" Text='<%# Bind("prison_event_id") %>' Visible="false"></asp:Label>
                                        <asp:Label ID="lblEvntDate" runat="server" Text='<%# Bind("prison_event_date") %>'
                                            Visible="false"></asp:Label></td>
                                    <asp:Label ID="lblEvntVenue" runat="server" Text='<%# Bind("prison_event_venue") %>'
                                        Visible="false"></asp:Label>
                                    <asp:TextBox ID="txtEvntDesc" runat="server" Text='<%# Bind("prison_event_description") %>'
                                        ReadOnly="true" Visible="false"></asp:TextBox>
                                    <asp:Button CommandName="Select" runat="server" Text="View Details" ID="btnEvntDetails">
                                    </asp:Button>
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </asp:DataList></div>
                <div id="body-right">
                    <table id="tblEvntDetails">
                        <tr>
                            <td>
                                <asp:Label ID="lblEvntId" runat="server" Visible="false"></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <asp:Label ID="lblEvntTitle" runat="server"></asp:Label></td>
                        </tr>
                        <tr>
                            <td>
                                <asp:Label ID="lblEvntDate" runat="server"></asp:Label></td>
                        </tr>
                        <tr>
                            <td>
                                <asp:Label ID="lblEvntVenue" runat="server"></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <asp:TextBox ID="txtEvntDesc" runat="server" ReadOnly="true"></asp:TextBox>
                            </td>
                        </tr>
                    </table>

the codebehind has the following code

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            this.loadData();

        }
    }

    protected void loadData()
    {

        BLL_NewsAndEvents objNe = new BLL_NewsAndEvents();
        objNe.viewEvents(this.dlEvents);
        objNe.Close();

    }
protected void SelectedIndexChanged(object sender, EventArgs e)
    {
       //  string ID = (String)dlEvents.DataKeyField;
       Label lblEvntId = (Label)dlEvents.SelectedItem.FindControl("lblEvntId");
        Label lblEvntTitle = (Label)dlEvents.SelectedItem.FindControl("lblEvntTitle");
        Label lblEvntDate = (Label)dlEvents.SelectedItem.FindControl("lblEvntDate");
        Label lblEvntVenue = (Label)dlEvents.SelectedItem.FindControl("lblEvntVenue");
        TextBox txtEvntDesc = (TextBox)dlEvents.SelectedItem.FindControl("txtEvntDesc");


    }

but when i run the code the get the following error:

DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'prison_event_id'.I have 'prison_event_id' in my table

please tell me wot to do

2
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by lisles
0

i have a datalist that displays the titles of events.When i click a title i want to display the event details like date,venue,description... outside the datalist
this is my code:

<asp:DataList ID="dlEvents" runat="server" HorizontalAlign="Left" GridLines="Both"
                        OnSelectedIndexChanged="SelectedIndexChanged">
                        <HeaderTemplate>
                            Events
                        </HeaderTemplate>
                        <HeaderStyle Font-Bold="true" Font-Size="16px" />
                        <ItemTemplate>
                            <table onmouseover="dg_changeBackColor(this, true);" onmouseout="dg_changeBackColor(this, false);">
                                <tr>
                                    <td>
                                        <%--  <asp:Label ID="lblEvntId" runat="server" Text='<%# Bind("prison_event_id") %>' Visible="false"></asp:Label>--%>
                                        <asp:Label ID="lblEvntTitle" runat="server" Text='<%# Bind("prison_event_title") %>'></asp:Label>
                                        <asp:Label ID="lblEvntId" runat="server" Text='<%# Bind("prison_event_id") %>' Visible="false"></asp:Label>
                                        <asp:Label ID="lblEvntDate" runat="server" Text='<%# Bind("prison_event_date") %>'
                                            Visible="false"></asp:Label></td>
                                    <asp:Label ID="lblEvntVenue" runat="server" Text='<%# Bind("prison_event_venue") %>'
                                        Visible="false"></asp:Label>
                                    <asp:TextBox ID="txtEvntDesc" runat="server" Text='<%# Bind("prison_event_description") %>'
                                        ReadOnly="true" Visible="false"></asp:TextBox>
                                    <asp:Button CommandName="Select" runat="server" Text="View Details" ID="btnEvntDetails">
                                    </asp:Button>
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </asp:DataList></div>
                <div id="body-right">
                    <table id="tblEvntDetails">
                        <tr>
                            <td>
                                <asp:Label ID="lblEvntId" runat="server" Visible="false"></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <asp:Label ID="lblEvntTitle" runat="server"></asp:Label></td>
                        </tr>
                        <tr>
                            <td>
                                <asp:Label ID="lblEvntDate" runat="server"></asp:Label></td>
                        </tr>
                        <tr>
                            <td>
                                <asp:Label ID="lblEvntVenue" runat="server"></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <asp:TextBox ID="txtEvntDesc" runat="server" ReadOnly="true"></asp:TextBox>
                            </td>
                        </tr>
                    </table>

the codebehind has the following code

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            this.loadData();

        }
    }

    protected void loadData()
    {

        BLL_NewsAndEvents objNe = new BLL_NewsAndEvents();
        objNe.viewEvents(this.dlEvents);
        objNe.Close();

    }
protected void SelectedIndexChanged(object sender, EventArgs e)
    {
       //  string ID = (String)dlEvents.DataKeyField;
       Label lblEvntId = (Label)dlEvents.SelectedItem.FindControl("lblEvntId");
        Label lblEvntTitle = (Label)dlEvents.SelectedItem.FindControl("lblEvntTitle");
        Label lblEvntDate = (Label)dlEvents.SelectedItem.FindControl("lblEvntDate");
        Label lblEvntVenue = (Label)dlEvents.SelectedItem.FindControl("lblEvntVenue");
        TextBox txtEvntDesc = (TextBox)dlEvents.SelectedItem.FindControl("txtEvntDesc");


    }

but when i run the code the get the following error:

DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'prison_event_id'.I have 'prison_event_id' in my table

please tell me wot to do

I guess you need to set DataKeyField property of DataList control with your prison_event_id .

0

thanx.I changed my code a bit...

<asp:DataList ID="dlEvents" runat="server" Width="90%" GridLines="both" CellPadding="5"
                          OnSelectedIndexChanged="SelectedIndexChanged" DataKeyField="prison_event_title">
                         <%--OnItemCommand="getSelected"--%>
                        <HeaderStyle BackColor="lightsteelblue"/>
                        <SelectedItemStyle BackColor="lightgreen" />
                        <HeaderTemplate>
                            Titles
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:LinkButton ID="Linkbutton1" runat="server" CommandName="select" Text='<%# Bind("prison_event_title") %>' />
                        </ItemTemplate>
                        <SelectedItemTemplate>
                            <asp:DataList ID="dlEvntDetails" runat="server">
                            <HeaderTemplate>
                            Event Details
                            </HeaderTemplate>
                            <ItemTemplate><div id="title" class="title" runat="server">
                                <asp:Label ID="lblEvntTitle" runat="server" Text='<%# Bind("prison_event_title") %>'></asp:Label></div>
                                <asp:Label ID="lblEvntId" runat="server" Text='<%# Bind("prison_event_id") %>' Visible="false"></asp:Label>
                                <asp:Label ID="lblEvntDate" runat="server" Text='<%# Bind("prison_event_date") %>'></asp:Label></td>
                                <asp:Label ID="lblEvntVenue" runat="server" Text='<%# Bind("prison_event_venue") %>'></asp:Label>
                                <asp:TextBox ID="txtEvntDesc" runat="server" Text='<%# Bind("prison_event_description") %>'
                                    ReadOnly="true"></asp:TextBox></ItemTemplate>
                            </asp:DataList>
                            
                            
                           
                        </SelectedItemTemplate>
                    </asp:DataList>

and thhe code behind is

protected void SelectedIndexChanged(object sender, EventArgs e)
    {
       
        Label lblEvntId = (Label)dlEvents.SelectedItem.FindControl("lblEvntId");
        Label lblEvntTitle = (Label)dlEvents.SelectedItem.FindControl("lblEvntTitle");
        Label lblEvntDate = (Label)dlEvents.SelectedItem.FindControl("lblEvntDate");
        Label lblEvntVenue = (Label)dlEvents.SelectedItem.FindControl("lblEvntVenue");
        TextBox txtEvntDesc = (TextBox)dlEvents.SelectedItem.FindControl("txtEvntDesc");
        DataList dlEvntDetails = (DataList)dlEvents.SelectedItem.FindControl("dlEvntDetails");
        BLL_NewsAndEvents objNE = new BLL_NewsAndEvents();
        objNE.viewEvntDetails(dlEvntDetails, txtEvntDesc.Text.Trim(), lblEvntVenue.Text.Trim(), lblEvntDate.Text.Trim(), lblEvntTitle.Text.Trim(), lblEvntId.Text.Trim());
        objNE.Close();
    
    }

but the values are not gettin passed to the codebehind...please tell me wot to do

0

can you please show the code of method viewEvents(this.dlEvents) and viewEventDetails() ? also i think you need to use ItemCreated or ItemDataBound event to show the other details you want...

0
public void viewEvents(System.Web.UI.WebControls.DataList dlToFill)
    {
        string[] arrParam = new string[1];
        arrParam[0] = "NA";
        bislogic objBis = new bislogic();
        objBis.populate_dataList(arrParam, dlToFill, "usp_event_viewDL");
        objBis.Close();
    }

when i try to put prison_event_id as datakeyfield the datalist doesnot display anythin....

0

im trying to get the name of the datalist that is nested within the main datalist in the selectedIndexChanged event...
i'm doing the following:

protected void SelectedIndexChanged(object sender, EventArgs e)
    {
        //string title = dlEvents.DataKeys[dlEvents.SelectedIndex].ToString(); 
        BLL_NewsAndEvents objNE = new BLL_NewsAndEvents();
        objNE.title = dlEvents.DataKeys[dlEvents.SelectedIndex].ToString();
       
        DataList dlEvntDetails = (DataList)dlEvents.FindControl("dlEvntDetails");
        objNE.getEvntDetails(dlEvntDetails);
        string id = objNE.Id.ToString();
        string title = objNE.title.ToString();
        //DateTime evntdate = objNE.evntDate;
        string venue = objNE.venue.ToString();
        string desc = objNE.Description.ToString();

but im not getting any value...please tell me how to get the name

0

i tried putting it in the ItemCommand Evnt

protected void getSelected(object source, DataListCommandEventArgs e)
    {
        dlEvents.SelectedIndex = e.Item.ItemIndex;
        DataList dlEvntDetails = (DataList)e.Item.FindControl("dlEvntDetails");
        BLL_NewsAndEvents objNE = new BLL_NewsAndEvents();
       objNE.title = dlEvents.DataKeys[dlEvents.SelectedIndex].ToString();
      
       objNE.getEvntDetails(dlEvntDetails);
        Label lblEvntId = (Label)e.Item.FindControl("lblEvntId");
        Label lblEvntTitle = (Label)e.Item.FindControl("lblEvntTitle");
        Label lblEvntDate = (Label)e.Item.FindControl("lblEvntDate");
        Label lblEvntVenue = (Label)e.Item.FindControl("lblEvntVenue");
        TextBox txtEvntDesc = (TextBox)e.Item.FindControl("txtEvntDesc");
        //DataList dlEvntDetails = (DataList)e.Item.FindControl("dlEvntDetails");
        BLL_NewsAndEvents objNe = new BLL_NewsAndEvents();

       // objNe.viewEvntDetails(dlEvntDetails, txtEvntDesc.Text.Trim(), lblEvntVenue.Text.Trim(), lblEvntDate.Text.Trim(), lblEvntTitle.Text.Trim(), lblEvntId.Text.Trim());
        objNe.Close();
    }

but still i cant get the value of the nested datalist...is there any other way i could do this...please help

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.