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

Manage a radlistview

3 Answers 86 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Fabio Cirillo
Top achievements
Rank 1
Fabio Cirillo asked on 03 Dec 2012, 10:45 AM
Hi,

i've a web page where insert a radlistview and connect to list of object...my code is:
As you can see there is a field userid, I wish that the value of the userid is passed on the button, is this possible?

<fieldset style="float: left; width: 340px; height: 195px">
                           <legend>Category:
                               <%# CType(Container.DataItem, PropertyUtente).Category%>
                           </legend>
                           <table cellpadding="0" cellspacing="0" width="95%">
                               <tr>
                                   <td style="width: 75%;">
                                       <table cellpadding="5" cellspacing="0">
                                           <tr>
                                               <td style="width: 25%;">
                                                   Userid:
                                               </td>
                                               <td style="width: 75%; text-align:left">
                                                   <%# CType(Container.DataItem, PropertyUtente).Userid%>
                                               </td>
                                           </tr>
                                           <tr>
                                               <td style="width: 25%;">
                                                   Name:
                                               </td>
                                               <td style="width: 75%; text-align:left">
                                                   <%# CType(Container.DataItem, PropertyUtente).user%>
                                               </td>
                                           </tr>
                                           <tr>
                                               <td>
                                                   City:
                                               </td>
                                               <td style="width: 75%; text-align:left">
                                                   <%# CType(Container.DataItem, PropertyUtente).city%>
                                               </td>
                                           </tr>
                                           <tr>
                                               <td>
                                                   Phone:
                                               </td>
                                               <td style="width: 75%; text-align:left">
                                                   <%# CType(Container.DataItem, PropertyUtente).phone%>
                                               </td>
                                           </tr>
                                           <tr>
                                               <td>
                                                   Cellular:
                                               </td>
                                               <td style="width: 75%; text-align:left">
                                                   <%# CType(Container.DataItem, PropertyUtente).Cellular%>
                                               </td>
                                           </tr>
                                           <tr>
                                               <td>
                                                </td>
                                               <td style="width: 75%; text-align:left">
                                                   <asp:Button ID="Button1" runat="server" Text="Details"  />
                                               </td>
                                           </tr>
                                       </table>
                                   </td>
                                    <td style="vertical-align: top; text-align: right; width: 25%;">
                                        <asp:Image ID="Image1" runat="server" ImageUrl='<%# CType(Container.DataItem, PropertyUtente).imageprofile%>' Height="120px" Width="100px"/>
                                   </td>                            
                               </tr>
                           </table>
                       </fieldset>

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 03 Dec 2012, 12:20 PM
Hi,

I suppose you want to get the value of userid on a button click. One suggestion is that you can set it as DataKeyNames and access it as shown below.
aspx:
<telerik:RadListView ID="RadListView1" runat="server"  DataKeyNames="Userid">
C#:
protected void Button1_Click(object sender, EventArgs e)
{
        Button button = sender as Button;
        RadListViewDataItem item = button.Parent as RadListViewDataItem;
        Response.Write(item.GetDataKeyValue("Userid"));
 }

Thanks,
Shinu.
0
Fabio Cirillo
Top achievements
Rank 1
answered on 03 Dec 2012, 12:50 PM
Hi,
i've written with vb net code so, but when start the page and start the debug to see if the vb code is execute, i see that the code is not executed...Why? where am I wrong?

<telerik:RadListView ID="RadListView1" runat="server"  DataKeyNames="Userid"
                    ItemPlaceholderID="Container" AllowPaging="True" PageSize="6" Skin="Simple">
                    <LayoutTemplate>
                        <fieldset id="FieldSet1">
                            <legend>Risultati della ricerca:</legend>
                            <asp:PlaceHolder ID="Container" runat="server"></asp:PlaceHolder>
                            <div style="clear: both">
                            </div>
                            <div>
                                <div style="float: left; margin-left: 30%;">
 <asp:Button runat="server" ID="btnFirst" CommandName="Page" CommandArgument="First"
 Text="Prima" Enabled="<%#Container.CurrentPageIndex > 0 %>"></asp:Button>
 <asp:Button runat="server" ID="btnPrev" CommandName="Page" CommandArgument="Prev"
 Text="Precedente" Enabled="<%#Container.CurrentPageIndex > 0 %>"></asp:Button>
                                    <span style="vertical-align: top; position: relative; top: 4px">Page
                                        <%#Container.CurrentPageIndex + 1 %>
                                        di
                                        <%#Container.PageCount %></span>
 <asp:Button runat="server" ID="btnNext" CommandName="Page" CommandArgument="Next"
 Text="Successivca" Enabled="<%#Container.CurrentPageIndex + 1 < Container.PageCount %>">
                                    </asp:Button>
 <asp:Button runat="server" ID="btnLast" CommandName="Page" CommandArgument="Last"
 Text="Ultima" Enabled="<%#Container.CurrentPageIndex + 1 < Container.PageCount %>">
                                    </asp:Button>
                                </div>
                            </div>
                        </fieldset>
                    </LayoutTemplate>
                    <ItemTemplate>
                        <fieldset style="float: left; width: 325px; height: 195px">
                            <legend>Category:
                                <%# CType(Container.DataItem, PropertyUtente).Category%>
                            </legend>
                            <table cellpadding="0" cellspacing="0" width="95%">
                                <tr>
                                    <td style="width: 80%;">
                                        <table cellpadding="4" cellspacing="0">
                                            <tr>
                                            </tr>
                                            <tr>
                                                <td style="width: 20%;">
                                                    Name:
                                                </td>
                                                <td style="width: 80%; text-align:left">
                                                    <%# CType(Container.DataItem, PropertyUtente).Name%>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td style="width: 20%;">
                                                    City:
                                                </td>
                                                <td style="width: 80%; text-align:left">
                                                    <%# CType(Container.DataItem, PropertyUtente).City%>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td style="width: 20%;">
                                                    Phone:
                                                </td>
                                                <td style="width: 80%; text-align:left">
                                                    <%# CType(Container.DataItem, PropertyUtente).Phone%>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td style="width: 20%;">
                                                    Cellular:
                                                </td>
                                                <td style="width: 80%; text-align:left">
                                                    <%# CType(Container.DataItem, PropertyUtente).Cellular%>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                </td>
                                                <td style="width: 100%; text-align:center">
                                                    <telerik:RadButton ID="RadButton1" runat="server" Text="View detail" Skin="Sunset">
                                                    </telerik:RadButton>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                     <td style="vertical-align: top; text-align: right; width: 100px;">
                                         <asp:Image ID="Image1" runat="server" ImageUrl='<%# CType(Container.DataItem, PropertyUtente).imageprofile%>' Height="120px" Width="100px"/>
                                    </td>                            
                                </tr>
                            </table>
                        </fieldset>
                    </ItemTemplate>
                </telerik:RadListView>
Protected Sub RadButton1_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim button As RadButton = CType(sender, RadButton)
    Dim item As RadListViewDataItem = CType(button.Parent, RadListViewDataItem)
    Response.Write(item.GetDataKeyValue("Userid"))
End Sub
0
Shinu
Top achievements
Rank 2
answered on 04 Dec 2012, 03:51 AM
Hi,

After inspecting your code I found that you are not attaching the click event of the RadButton. Please make sure that you are attaching the click event to the RadButton and let me know if you need further assistance.

ASPX:
<telerik:RadButton ID="RadButton1" runat="server" Text="View detail" Skin="Sunset"  OnClick="RadButton1_Click">
</telerik:RadButton>

C#:
Protected Sub RadButton1_Click(sender As Object, e As EventArgs)
    Dim button As RadButton = TryCast(sender, RadButton)
    Dim item As RadListViewDataItem = TryCast(button.Parent, RadListViewDataItem)
    Response.Write(item.GetDataKeyValue("CustomerID"))
End Sub

Thanks,
Shinu.
Tags
ListView
Asked by
Fabio Cirillo
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Fabio Cirillo
Top achievements
Rank 1
Share this question
or