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

[Solved] Getting values out of GridTemplateColumn Controls for Saving

1 Answer 233 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pierre
Top achievements
Rank 1
Pierre asked on 16 Oct 2009, 09:26 AM
Hi there,

I am developing a Evaluation Control where Questions are listed and I need to get the following from the Grid to save as a 'Answer' to each of the Questions listed in the Grid:

~ The True/False Reply associated to a Question. [Basically which RadioButton is selected.]
~ Then also the Notes associated to a Question. [The Value from the TextBox.]

I am doing all my binding from the Code-behind. So I basically have to iterate through each bound row in the Grid and then persist the 'Answers' whan the Save Button is pressed.

Here is the Grid Markup:

<telerik:RadGrid ID="radgridList" runat="server" AllowSorting="False" AutoGenerateColumns="False" 
        GridLines="none" OnNeedDataSource="radgridList_NeedDataSource"
        <MasterTableView Width="100%"
            <GroupByExpressions> 
                <telerik:GridGroupByExpression> 
                    <SelectFields> 
                        <telerik:GridGroupByField FieldAlias="Catergory" FieldName="Title"></telerik:GridGroupByField> 
                    </SelectFields> 
                    <GroupByFields> 
                        <telerik:GridGroupByField FieldName="Title" SortOrder="Descending"></telerik:GridGroupByField> 
                    </GroupByFields> 
                </telerik:GridGroupByExpression> 
            </GroupByExpressions> 
            <Columns> 
                <telerik:GridBoundColumn HeaderText="QuestionId" DataField="QuestionId" UniqueName="QuestionId" 
                    Visible="False"
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn HeaderText="Body" DataField="Body" UniqueName="Body"
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn HeaderText="Weighting" DataField="Weighting" UniqueName="Weighting"
                </telerik:GridBoundColumn> 
                <telerik:GridTemplateColumn HeaderText="True" UniqueName="TrueSelection"
                    <ItemTemplate> 
                        <asp:RadioButton ID="rbTrue" runat="server" GroupName="Selection" /> 
                    </ItemTemplate> 
                </telerik:GridTemplateColumn> 
                <telerik:GridTemplateColumn HeaderText="False" UniqueName="FalseSelection"
                    <ItemTemplate> 
                        <asp:RadioButton ID="rbFalse" runat="server" GroupName="Selection" Checked="True" /> 
                    </ItemTemplate> 
                </telerik:GridTemplateColumn> 
                <telerik:GridTemplateColumn HeaderText="Notes" UniqueName="Notes"
                    <ItemTemplate> 
                        <telerik:RadTextBox ID="txtNotes" runat="server" Width="250px"
                        </telerik:RadTextBox> 
                    </ItemTemplate> 
                </telerik:GridTemplateColumn> 
            </Columns> 
        </MasterTableView> 
        <ClientSettings> 
            <Selecting></Selecting
            <Resizing AllowRowResize="True" AllowColumnResize="True" EnableRealTimeResize="True" 
                ResizeGridOnColumnResize="False"></Resizing> 
        </ClientSettings> 
        <GroupingSettings ShowUnGroupButton="true" /> 
    </telerik:RadGrid> 
    <div id="bottom" style="float:right; padding-top:10px;"
    <asp:Button ID="btnSave" Text="Save" runat="server" CausesValidation="True" onclick="btnSave_Click" /></div

Any help as to how best to achieve the above functionality will be much appreciated.

Thanks!

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 16 Oct 2009, 10:25 AM
Hello Pierre,

You can try out the following code to extract the template column data on clicking the save button:
c#:
protected void btnSave_Click(object sender, EventArgs e) 
    { 
        foreach (GridDataItem item in RadGrid1.Items) 
        { 
            RadioButton rdbtn1 = (RadioButton)item.FindControl("rbTrue"); 
            RadioButton rdbtn2 = (RadioButton)item.FindControl("rbFalse"); 
            RadTextBox txtbx = (RadTextBox)item.FindControl("txtNotes"); 
            string strtxt1 = rdbtn1.Checked.ToString(); 
            string strtxt2 = rdbtn2.Checked.ToString(); 
            string strtxt3 = txtbx.Text; 
 
            // update database 
 
        } 
    } 

Thanks
Princy.
Tags
Grid
Asked by
Pierre
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or