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

Insert Item Template Help

1 Answer 126 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Dave
Top achievements
Rank 1
Dave asked on 26 Jul 2011, 04:15 AM
I am trying to insert data from a listview Insert Item Template into my datasource.  There are 2 fields that the user doesn't enter, but instead come from application variables.  How do I put these into the insert item template, or into the sql datasource insert?

1 Answer, 1 is accepted

Sort by
0
Thad
Top achievements
Rank 2
answered on 03 Aug 2011, 01:11 AM
Hi Dave,

This should be what you need. It's easier to do it this way (in my opinion) than to try to modify the datasource.

Add an event handler for ItemDataBound event.
<telerik:RadListView ID="rlvTest" runat="server" OnItemDataBound="rlvTest_ItemDataBound">
    <InsertItemTemplate>
        <asp:Label ID="lblId" runat="server" />
    </InsertItemTemplate>
</telerik:RadListView>

In this event, check to see if the type of item being bound is an InsertItem, and if it is then find the control and set the value as you desire.
protected void rlvTest_ItemDataBound(object sender, RadListViewItemEventArgs e)
{
    if (e.Item.ItemType == RadListViewItemType.InsertItem)
    {
        Label label = e.Item.FindControl("lblId") as Label;
        if (label != null)
        {
            label.Text = SomeApplicationVariable;
        }
    }
}

Hope that helps!
Thad
Tags
ListView
Asked by
Dave
Top achievements
Rank 1
Answers by
Thad
Top achievements
Rank 2
Share this question
or