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

User Controls in template with datasource Parameters

2 Answers 276 Views
Grid
This is a migrated thread and some comments may be shown as answers.
-Tony
Top achievements
Rank 1
-Tony asked on 28 Jan 2014, 09:26 PM
Hi,
Is there a way to use data source control parameters with user controls in a rad grid template?  I added the insert template code where the user control is used (textbox1) and the data source code portion where I try to use a textbox1 as a control parameter for the data source, I get the error: Could not find control 'txtbox1' in ControlParameter 'Answer1'.
<telerik:GridTemplateColumn DataField="Answer1"
            FilterControlAltText="Filter Answer1 column" HeaderText="Answer1"
            SortExpression="Answer1" UniqueName="Answer1" Visible="False">
            <InsertItemTemplate>
                <asp:TextBox ID="txtbox1"  runat="server"></asp:TextBox>
            </InsertItemTemplate>
        </telerik:GridTemplateColumn>
    </Columns>


<asp:SqlDataSource ID="QuestionIDDatasource" runat="server"
       ConnectionString="<%$ ConnectionStrings:TESTGAMEConnectionString %>"
        
       SelectCommand="SELECT Questions.QuestionID, QuestionText.QuestionsText, Language.LanguageName, QuestionType.QuestionTypeName, Scenario.ScenarioName, Badges.BadgeName, QuestionType.QuestionTypeID, Badges.BadgeID, Scenario.ScenarioID, QuestionText.QuestionTextID, Language.LanguageID FROM Badges RIGHT OUTER JOIN Questions LEFT OUTER JOIN QuestionType ON Questions.QuestionTypeID = QuestionType.QuestionTypeID ON Badges.BadgeID = Questions.BadgeID LEFT OUTER JOIN Scenario ON Questions.ScenarioID = Scenario.ScenarioID LEFT OUTER JOIN Language INNER JOIN QuestionText ON Language.LanguageID = QuestionText.LanguageID ON Questions.QuestionID = QuestionText.QuestionID WHERE (Questions.EventID = @EventID)"
       InsertCommand="sp_questions_INS"
       UpdateCommand="UPDATE Questions SET QuestionTypeID = @QuestionTypeID, BadgeID = @BadgeID, ScenarioID = @ScenarioID WHERE (QuestionID = @QuestionID)"
       InsertCommandType="StoredProcedure">
       <InsertParameters>
             <asp:ControlParameter  ControlID="CurrentEvent" Name="EventID" PropertyName="Value"
               Type="Int32"/>
               <asp:ControlParameter  ControlID="txtbox1" Name="Answer1" PropertyName= "text"
               Type="String"/>
                <asp:ControlParameter  ControlID="ddLanguage" Name="LanguageID" PropertyName= "SelectedValue"
               Type="Int32"/>
           <asp:Parameter Name="ScenarioID" />
           <asp:Parameter Name="BadgeID" />
           <asp:Parameter Name="QuestionTypeID" />
             <asp:Parameter Name="QuestionsText" Type="String" />
             <asp:Parameter Name="QuestionID" Type="Int32" />
              
       </InsertParameters>

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 29 Jan 2014, 12:13 PM
Hi Tony,

You can set the Control Parameter from code behind.I suggest you to initialize the SqlDataSource’s control parameters within the RadGrid.ItemCreated event handler and set the ControlID to the control’s UniqueID:

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted) //Check if Insert Mode
    {
        GridEditFormInsertItem edit = e.Item as GridEditFormInsertItem;
        TextBox txt = edit.FindControl("txtbox1") as TextBox;   // Access the TextBox in InsertTemplate        
        ControlParameter parameter = new ControlParameter("txtbox1", txt.UniqueID, "text");
        this.QuestionIDDatasource.InsertParameters.Add(parameter);           
    }
}

Thanks,
Princy
0
-Tony
Top achievements
Rank 1
answered on 29 Jan 2014, 05:34 PM
Just what I needed thank you Princy.
Tags
Grid
Asked by
-Tony
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
-Tony
Top achievements
Rank 1
Share this question
or