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

Different insert actions

2 Answers 139 Views
Grid
This is a migrated thread and some comments may be shown as answers.
fahd
Top achievements
Rank 1
fahd asked on 07 Apr 2012, 08:06 PM
<CommandItemTemplate>                                               
    <div style="width:100%; height:100%;">
        <asp:LinkButton ID="btnAddDropShipSubjectArea" runat="server" CommandArgument="SubjectArea" CommandName="InitInsert">
<
img style="border:0px" alt="" src="../CSS/View/Grid/AddRecord_ToolTip.gif" /> Add Subject Area
        </asp:LinkButton>
        <asp:LinkButton ID="btnAddDropShipItem" runat="server" CommandArgument="Item" CommandName="InitInsert">
<
img style="border:0px" alt="" src="../CSS/View/Grid/AddRecord_ToolTip.gif" /> Add Item
        </asp:LinkButton>
    </div>
</CommandItemTemplate>  
<Columns>
    <telerik:GridDropDownColumn Visible="false" UniqueName="ddlSubjectAreaCodes" DataField="IntAreaCode_SK"
        HeaderText="ID" DropDownControlType="RadComboBox" AutoPostBackOnFilter="true">
    </telerik:GridDropDownColumn>
</Columns> 

I have a grid with the markup above. I have two link buttons that do two different things; I couldn't find
out how to populate ddlSubjectAreaCodes with different data based on the link clicked in the ItemCreated
event.
Any help is appreciated.
Thanks

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 09 Apr 2012, 05:41 AM
Hi Fahd,

Here is the code snippet I tried to populate the GridDropDownColumn with different data based on different Linkbutton Click.

C#:
string data = string.Empty;
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
    if (e.CommandArgument == "SubjectArea")
    {
        data = "subject";
    }
    if (e.CommandArgument == "Item")
    {
        data = "item";
    }
}
 
 
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditableItem eitem = (GridEditableItem)e.Item;
        RadComboBox rdbx = (RadComboBox)eitem["ddlSubjectAreaCodes"].Controls[0];
        if (data == "subject")
        {
 
            rdbx.DataSourceID = "SqlDataSource1";
            rdbx.DataTextField = "ShipName";
            rdbx.DataValueField = "ShipName";
        }
        else
        {
 
            rdbx.DataSourceID = "SqlDataSource1";
            rdbx.DataTextField = "OrderID";
            rdbx.DataValueField = "OrderID";
 
        }
    }
}

Thanks,
Shinu.
0
fahd
Top achievements
Rank 1
answered on 10 Apr 2012, 01:18 PM
Thank you for your reply, but I used the viewstate instead.
Tags
Grid
Asked by
fahd
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
fahd
Top achievements
Rank 1
Share this question
or