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

Declare textbox variables

4 Answers 223 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Parodist
Top achievements
Rank 1
Parodist asked on 31 Jan 2009, 01:02 PM
I have the following code to display in my radgrid in a textbox with an id =txtComments but how do declare this variable to write an insert query in CS.
Similarly, if we add other controls within the radgrid,how can we display all the added controls in a messagebox to identify its row indexes?
Thanking you in advance !!

 

<telerik:GridTemplateColumn HeaderText="Comments" HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Center">  
<ItemTemplate> 
<asp:TextBox ID="txtComments" runat="server" /> 
</ItemTemplate> 
</telerik:GridTemplateColumn> 
 

 

 

 

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 02 Feb 2009, 05:16 AM
Hi,

I am not sure about your requirement. From what I understood so far I guess you are trying to access the value of the TextBox inside a GridTemplateColumn and perform an Insert Operation on clicking a button in the same row. If so you can try the following approach.

ASPX:
<telerik:GridTemplateColumn HeaderText="Comments" UniqueName="TempCol" HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Center">   
<ItemTemplate> 
<asp:TextBox ID="txtComments" runat="server" /> 
</ItemTemplate> 
</telerik:GridTemplateColumn> 
 
 <telerik:GridButtonColumn Text="InsertValue"  CommandName="InsertValue" ButtonType="LinkButton" ></telerik:GridButtonColumn> 


CS:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.CommandName == "InsertValue"
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            TextBox txtbx = (TextBox)item["TempCol"].FindControl("txtComments"); 
            string strcomments = txtbx.Text;
            // Perform Insert Operation here 
        } 
         
    } 


One another suggestion is to use the AutoGeneratedInsert form on clickingn AddNewRecord button on the top of the Grid. For achieving this you need to set the CommandItemDisplay to top and also place the controls in the EditItemTemplate of the GridTemplateColumn.

Thanks
Shinu
0
Parodist
Top achievements
Rank 1
answered on 02 Feb 2009, 07:02 AM
Thanks for the reply Shinu,I have the insert button (btnInsert_Click1) common for all which includes normal text boxes displayed outside the radgrid .So how can I use a single insert button instead of using (e.CommandName == "InsertValue") .


Thanking you in advance.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Minsert.aspx.cs" Inherits="Minsert" 
    MasterPageFile="~/MasterPage2.master" %> 
 
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<%--<%@ Register TagPrefix="sds" Namespace="Telerik.Web.SessionDS" %>--%> 
<asp:Content ID="ContentHead" ContentPlaceHolderID="head" runat="server">  
    <link href="style.css" rel="stylesheet" type="text/css" /> 
</asp:Content> 
<asp:Content ID="content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">  
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">  
    </telerik:RadScriptManager> 
    <table style="width: 100%;" onload="findhiddenfield()">  
        <tr> 
            <td colspan="4" style="text-align: center">  
                <span class="mainhead">Monitoring Shift Handover</span> 
            </td> 
        </tr> 
        <tr> 
            <td colspan="2" style="text-align: center">  
                Shift handed over by  
            </td> 
            <td colspan="2" style="text-align: center">  
                Shift taken over by  
            </td> 
        </tr> 
        <tr> 
            <td> 
                Date  
            </td> 
            <td> 
                <telerik:RadDatePicker ID="RadDatePicker1" runat="server" CssClass="textbox120" Width="220px">  
                    <DateInput InvalidStyleDuration="100">  
                    </DateInput> 
                </telerik:RadDatePicker> 
            </td> 
            <td> 
                Date  
            </td> 
            <td> 
                <telerik:RadDatePicker ID="RadDatePicker2" runat="server" CssClass="textbox120" Width="220px">  
                    <DateInput InvalidStyleDuration="100">  
                    </DateInput> 
                </telerik:RadDatePicker> 
            </td> 
        </tr> 
        <tr> 
            <td> 
                Engineer  
            </td> 
            <td> 
                <asp:TextBox ID="txtEngineer" runat="server" CssClass="textbox120" Width="220px"></asp:TextBox> 
            </td> 
            <td> 
                Engineer  
            </td> 
            <td> 
                <asp:TextBox ID="txtEngineerTakenOver" runat="server" CssClass="textbox120" Width="220px"></asp:TextBox> 
            </td> 
        </tr> 
        <tr> 
            <td> 
                &nbsp;  
            </td> 
            <td> 
                &nbsp;  
            </td> 
            <td> 
                &nbsp;  
            </td> 
            <td> 
                &nbsp;  
            </td> 
        </tr> 
        <table> 
            <tr> 
                <td> 
                    <cc1:Accordion ID="Accordion1" runat="server" SelectedIndex="1" HeaderCssClass="accordionHeader" 
                        HeaderSelectedCssClass="accordionHeaderSelected" ContentCssClass="accordionContent" 
                        AutoSize="None" FadeTransitions="true" TransitionDuration="250" FramesPerSecond="40" 
                        RequireOpenedPane="false" SuppressHeaderPostbacks="true">  
                        <Panes> 
                            <cc1:AccordionPane ID="AccordionPane1" runat="server" HeaderCssClass="accordionHeader" 
                                HeaderSelectedCssClass="accordionHeaderSelected" ContentCssClass="accordionContent">  
                                <Header> 
                                    <href="" onclick="return false;" class="accordionlink" style="text-align: left">  
                                    </a>Shift details</Header> 
                                <Content> 
                                    <table> 
                                        <tr> 
                                            <td class="">  
                                                Morning  
                                            </td> 
                                            <td class="" colspan="3">  
                                                <asp:TextBox ID="txtMorning" runat="server" Height="80px" TextMode="MultiLine" Width="600px" 
                                                    CssClass="textbox120"></asp:TextBox> 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td class="">  
                                                Evening  
                                            </td> 
                                            <td class="" colspan="3">  
                                                <asp:TextBox ID="txtEvening" runat="server" Height="80px" TextMode="Multiline" Width="600px" 
                                                    Style="text-align: left" CssClass="textbox120"></asp:TextBox> 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td class="">  
                                                Night  
                                            </td> 
                                            <td class="" colspan="3">  
                                                <asp:TextBox ID="txtNight" runat="server" Height="80px" TextMode="Multiline" Width="600px" 
                                                    CssClass="textbox120"></asp:TextBox> 
                                            </td> 
                                        </tr> 
                                    </table> 
                                </Content> 
                            </cc1:AccordionPane> 
                        </Panes> 
                    </cc1:Accordion> 
                </td> 
            </tr> 
            <tr> 
                <td> 
                    <cc1:Accordion ID="Accordion2" runat="server" SelectedIndex="1" HeaderCssClass="accordionHeader" 
                        HeaderSelectedCssClass="accordionHeaderSelected" ContentCssClass="accordionContent" 
                        AutoSize="None" FadeTransitions="true" TransitionDuration="250" FramesPerSecond="40" 
                        RequireOpenedPane="false" SuppressHeaderPostbacks="true">  
                        <Panes> 
                            <cc1:AccordionPane ID="AccordionPane2" runat="server" HeaderCssClass="accordionHeader" 
                                HeaderSelectedCssClass="accordionHeaderSelected" ContentCssClass="accordionContent">  
                                <Header> 
                                    <href="" onclick="return false;" class="accordionlink"></a>Important Follow ups</Header> 
                                <Content> 
                                    <table> 
                                        <tr> 
                                            <td class="">  
                                                <asp:TextBox ID="txtImpFollowUps" runat="server" Height="73px" TextMode="MultiLine" 
                                                    Width="660px" Style="text-align: left" CssClass="textbox120"></asp:TextBox> 
                                            </td> 
                                        </tr> 
                                    </table> 
                                </Content> 
                            </cc1:AccordionPane> 
                        </Panes> 
                    </cc1:Accordion> 
                </td> 
            </tr> 
            <tr> 
                <td> 
                    <cc1:Accordion ID="Accordion3" runat="server" SelectedIndex="1" HeaderCssClass="accordionHeader" 
                        HeaderSelectedCssClass="accordionHeaderSelected" ContentCssClass="accordionContent" 
                        AutoSize="None" FadeTransitions="true" TransitionDuration="250" FramesPerSecond="40" 
                        RequireOpenedPane="false" SuppressHeaderPostbacks="true" Style="text-align: center">  
                        <Panes> 
                            <cc1:AccordionPane ID="AccordionPane3" runat="server" HeaderCssClass="accordionHeader" 
                                HeaderSelectedCssClass="accordionHeaderSelected" ContentCssClass="accordionContent">  
                                <Header> 
                                    <href="" onclick="return false;" class="accordionlink"></a>Sheduled activity</Header> 
                                <Content> 
                                    <table> 
                                        <tr> 
                                            <td> 
                                                <table style="width: 100%;">  
                                                    <tr> 
                                                        <td align="left">  
                                                            <telerik:RadComboBox ID="RadComboBox1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged" 
                                                                RadComboBoxImagePosition="right" Width="200px" Skin="Vista">  
                                                            </telerik:RadComboBox> 
                                                            <asp:Label ID="lblMessage" runat="server" Text="Label" Visible="false"></asp:Label> 
                                                            <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" GridLines="None" 
                                                                Style="text-align: center" HorizontalAlign="Left" Skin="Vista">  
                                                                <ClientSettings> 
                                                                    <Selecting AllowRowSelect="false" EnableDragToSelectRows="false" /> 
                                                                </ClientSettings> 
                                                                <MasterTableView CommandItemDisplay="None" HorizontalAlign="Center">  
                                                                    <RowIndicatorColumn Visible="False">  
                                                                        <HeaderStyle Width="20px"></HeaderStyle> 
                                                                    </RowIndicatorColumn> 
                                                                    <ExpandCollapseColumn Visible="False" Resizable="False">  
                                                                        <HeaderStyle Width="20px"></HeaderStyle> 
                                                                    </ExpandCollapseColumn> 
                                                                    <Columns> 
                                                                        <telerik:GridBoundColumn DataField="Id" Visible="true" HeaderText="Id" UniqueName="Id" 
                                                                            ReadOnly="True">  
                                                                        </telerik:GridBoundColumn> 
                                                                        <telerik:GridBoundColumn DataField="Activity" HeaderText="Activity" SortExpression="Activity" 
                                                                            UniqueName="Activity" HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Center">  
                                                                        </telerik:GridBoundColumn> 
                                                                        <telerik:GridTemplateColumn HeaderText="Status" UniqueName="TempCol1" HeaderStyle-Font-Bold="true" 
                                                                            HeaderStyle-HorizontalAlign="Center">  
                                                                            <ItemTemplate> 
                                                                                <asp:TextBox ID="txtStatus" runat="server" /> 
                                                                            </ItemTemplate> 
                                                                        </telerik:GridTemplateColumn> 
                                                                        <telerik:GridTemplateColumn HeaderText="Comments" UniqueName="TempCol2" HeaderStyle-Font-Bold="true" 
                                                                            HeaderStyle-HorizontalAlign="Center">  
                                                                            <ItemTemplate> 
                                                                                <asp:TextBox ID="txtComments" runat="server" /> 
                                                                            </ItemTemplate> 
                                                                        </telerik:GridTemplateColumn> 
                                                                    </Columns> 
                                                                    <EditFormSettings> 
                                                                        <PopUpSettings ScrollBars="None"></PopUpSettings> 
                                                                    </EditFormSettings> 
                                                                </MasterTableView> 
                                                            </telerik:RadGrid> 
                                                        </td> 
                                                        <td> 
                                                        </td> 
                                                        <td> 
                                                        </td> 
                                                        <td> 
                                                        </td> 
                                                        <td> 
                                                            &nbsp;  
                                                        </td> 
                                                        <td> 
                                                            &nbsp;  
                                                        </td> 
                                                    </tr> 
                                                    <tr> 
                                                        <td> 
                                                            &nbsp;  
                                                        </td> 
                                                        <td> 
                                                            &nbsp;  
                                                        </td> 
                                                        <td> 
                                                            &nbsp;  
                                                        </td> 
                                                    </tr> 
                                                </table> 
                                            </td> 
                                        </tr> 
                                    </table> 
                                </Content> 
                            </cc1:AccordionPane> 
                        </Panes> 
                    </cc1:Accordion> 
                </td> 
            </tr> 
            <tr> 
                <td> 
                    <cc1:Accordion ID="Accordion4" runat="server" SelectedIndex="1" HeaderCssClass="accordionHeader" 
                        HeaderSelectedCssClass="accordionHeaderSelected" ContentCssClass="accordionContent" 
                        AutoSize="None" FadeTransitions="true" TransitionDuration="250" FramesPerSecond="40" 
                        RequireOpenedPane="false" SuppressHeaderPostbacks="true">  
                        <Panes> 
                            <cc1:AccordionPane ID="AccordionPane4" runat="server" HeaderCssClass="accordionHeader" 
                                HeaderSelectedCssClass="accordionHeaderSelected" ContentCssClass="accordionContent">  
                                <Header> 
                                    <href="" onclick="return false;" class="accordionlink"></a>Latest updates</Header> 
                                <Content> 
                                    <table> 
                                        <tr> 
                                            <td> 
                                                <asp:TextBox ID="txtLatestUpdates" runat="server" Height="73px" Style="text-align: left" 
                                                    TextMode="MultiLine" Width="660px" CssClass="textbox120"></asp:TextBox> 
                                            </td> 
                                        </tr> 
                                    </table> 
                                </Content> 
                            </cc1:AccordionPane> 
                        </Panes> 
                    </cc1:Accordion> 
                </td> 
            </tr> 
            <tr> 
                <td> 
                    <cc1:Accordion ID="Accordion5" runat="server" SelectedIndex="1" HeaderCssClass="accordionHeader" 
                        HeaderSelectedCssClass="accordionHeaderSelected" ContentCssClass="accordionContent" 
                        AutoSize="None" FadeTransitions="true" TransitionDuration="250" FramesPerSecond="40" 
                        RequireOpenedPane="false" SuppressHeaderPostbacks="true">  
                        <Panes> 
                            <cc1:AccordionPane ID="AccordionPane7" runat="server" HeaderCssClass="accordionHeader" 
                                HeaderSelectedCssClass="accordionHeaderSelected" ContentCssClass="accordionContent">  
                                <Header> 
                                    <href="" onclick="return false;" class="accordionlink"></a>For Your Information  
                                </Header> 
                                <Content> 
                                    <table> 
                                        <tr> 
                                            <td> 
                                                <asp:TextBox ID="txtFYI" runat="server" Height="73px" Style="text-align: left" TextMode="MultiLine" 
                                                    Width="660px" CssClass="textbox120"></asp:TextBox> 
                                            </td> 
                                        </tr> 
                                    </table> 
                                </Content> 
                            </cc1:AccordionPane> 
                        </Panes> 
                    </cc1:Accordion> 
                </td> 
            </tr> 
            <tr> 
                <td> 
                    &nbsp;  
                </td> 
            </tr> 
            <tr> 
                <td style="text-align: center">  
                    <asp:Button ID="btnInsert" runat="server" CssClass="button" Text="Insert" OnClick="btnInsert_Click1" /> 
                    <asp:Button ID="btnReset" runat="server" CssClass="button" Text="Reset" OnClick="btnReset_Click" /> 
                </td> 
            </tr> 
            <tr> 
                <td> 
                    &nbsp;  
                </td> 
            </tr> 
        </table> 
        <tr> 
            <td> 
                &nbsp;  
            </td> 
            <td> 
                &nbsp;  
            </td> 
            <td> 
                &nbsp;  
            </td> 
            <td> 
                &nbsp;  
            </td> 
        </tr> 
        <tr> 
            <td> 
                &nbsp;  
            </td> 
            <td> 
                &nbsp;  
            </td> 
            <td> 
                &nbsp;  
            </td> 
            <td> 
                &nbsp;  
            </td> 
        </tr> 
    </table> 
</asp:Content> 
 
0
Princy
Top achievements
Rank 2
answered on 02 Feb 2009, 10:53 AM
Hi Parodist,

Try the below code snippets to access the TextBox in the TemplateColumn. And since the RadGrid is placed inside Accordion, first get the RadGrid as shown below.

CS:
protected void Button1_Click(object sender, EventArgs e)  
{  
      RadGrid Grid=(RadGrid)Accordion1.FindControl("RadGrid1"); 
      foreach (GridDataItem item in Grid.MasterTableView.Items)  
      {  
          TextBox txtbx = (TextBox)item["TempCol"].FindControl("TextBox1");   
      }  

Thanks,
Princy.
1
MANU
Top achievements
Rank 1
answered on 02 Feb 2009, 12:57 PM
Excellent Princy molu,,

My application is working now................

Luv u

MANU
Tags
Grid
Asked by
Parodist
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Parodist
Top achievements
Rank 1
Princy
Top achievements
Rank 2
MANU
Top achievements
Rank 1
Share this question
or