RadioButtonList in RadGrid

14 posts, 2 answers
  1. Yuriy
    Yuriy avatar
    13 posts
    Member since:
    Jul 2011

    Posted 04 Dec 2011 Link to this post

    Hi there,

    I need to buid a survey interface and thought that RadGrid could be a good candidate for it.
    I have two datasources:
    1. with questions, with related key;
    2. answers, which has a reference to the question key.

    Idea is that I would have a radgrid with two columns:
    1. Question as bound coulmn
    2. RadioButtonList with answers.

    The problem is that I can not get two datasources marry by the question key. When I pass a parameter to answers datasource as a control radgrid SelectedValue, the second column is not showing up at all. Any recommendations would be appreciated. I paste my code below.

    Thanks,
    Yuriy

     

    <telerik:RadGrid ID="RadGrid1" runat="server" CellSpacing="0" DataSourceID="sqlManufacturerSurvey" 
    GridLines="None" AutoGenerateColumns="False"
    <MasterTableView DataSourceID="sqlManufacturerSurvey" DataKeyNames="QuestionID" Name="Questions" 
    HierarchyLoadMode="Client"
    <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings
    <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column"
    <HeaderStyle Width="20px"></HeaderStyle
    </RowIndicatorColumn
    <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column"
    <HeaderStyle Width="20px"></HeaderStyle
    </ExpandCollapseColumn
    <Columns
    <telerik:GridBoundColumn DataField="QuestionID" FilterControlAltText="Filter QuestionID column" 
    HeaderText="QuestionID" UniqueName="QuestionID"
    </telerik:GridBoundColumn
    <telerik:GridBoundColumn DataField="Question" FilterControlAltText="Filter Question column" 
    HeaderText="Question" UniqueName="Question"
    </telerik:GridBoundColumn
    <telerik:GridTemplateColumn FilterControlAltText="Filter column column" UniqueName="Answer" 
    HeaderText="Answer"
    <ItemTemplate
    <asp:RadioButtonList ID="rblAnswer" runat="server" DataSourceID="sqlResponses" DataTextField="Answer" 
    DataValueField="AnswerID" RepeatLayout="Table"
    </asp:RadioButtonList
    </ItemTemplate
    </telerik:GridTemplateColumn
    </Columns
    <EditFormSettings
    <EditColumn FilterControlAltText="Filter EditCommandColumn column"
    </EditColumn
    </EditFormSettings
    </MasterTableView
    <FilterMenu EnableImageSprites="False"
    <WebServiceSettings
    <ODataSettings InitialContainerName=""
    </ODataSettings
    </WebServiceSettings
    </FilterMenu
    <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default"
    <WebServiceSettings
    <ODataSettings InitialContainerName=""
    </ODataSettings
    </WebServiceSettings
    </HeaderContextMenu
    </telerik:RadGrid
    <asp:SqlDataSource ID="sqlManufacturerSurvey" runat="server" ConnectionString="<%$ ConnectionStrings:KPortal %>" 
    SelectCommand="SELECT MaterialCategory.ServiceTypeID, Question.MaterialID AS QuestionID, Question.MaterialName AS Question FROM MaterialCategory INNER JOIN Materials AS Question ON MaterialCategory.MaterialCategoryID = Question.MaterialCategoryID WHERE (MaterialCategory.MaterialCategory = 'Manufacturer Survey') AND (Question.InternalCode = 'QUESTION')"> 
    </asp:SqlDataSource
    <asp:SqlDataSource ID="sqlResponses" runat="server" ConnectionString="<%$ ConnectionStrings:KPortal %>" 
    SelectCommand="SELECT MaterialID AnswerID, MaterialName as Answer, ParentMaterialID as QuestionID FROM Materials WHERE (ParentMaterialID = @QuestionID)"> 
    <SelectParameters
    <asp:ControlParameter ControlID="RadGrid1" Name="QuestionID" 
    PropertyName="SelectedValue" /> 
    </SelectParameters
    </asp:SqlDataSource
  2. Answer
    Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 05 Dec 2011 Link to this post

    Hello,

    You can also assign datasource dynamically.
    <MasterTableView DataKeyNames="QuestionId"></MasterTableView>

    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = e.Item as GridDataItem;
                RadioButtonList rblAnswer = item.FindControl("rblAnswer") as RadioButtonList;
                 
                SqlDataSource sqlDS = new SqlDataSource();
                sqlDS.ConnectionString = "your conncetion string";
                sqlDS.SelectCommand = "select * from Table1 Where QuestionId =" + item.GetDataKeyValue("QuestionId").ToString();
                rblAnswer.DataSource = sqlDS;
    .........
    ..........
            }
        }

    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Yuriy
    Yuriy avatar
    13 posts
    Member since:
    Jul 2011

    Posted 05 Dec 2011 Link to this post

    Hi Jayesh,

    Something is still missing, cause the control is not showing up on the grid, I am still getting empty cell. Should I also do something about rendering values in this radiobuttonlist control, or this is happening automatically?
    This is the definition of control and c# code behind.

    <telerik:GridTemplateColumn FilterControlAltText="Filter column column" UniqueName="Answer"
        HeaderText="Answer">
        <ItemTemplate>
            <asp:RadioButtonList ID="rblAnswer" runat="server"  DataTextField="Answer"
                DataValueField="AnswerID" RepeatLayout="Table">
            </asp:RadioButtonList>
        </ItemTemplate>
    </telerik:GridTemplateColumn>


    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
     
        if (e.Item is GridDataItem)
     
    {
        GridDataItem item = e.Item as GridDataItem;
        RadioButtonList rblAnswer = item.FindControl("rblAnswer") as RadioButtonList;
     
        SqlDataSource sqlDS = new SqlDataSource();
        sqlDS.ConnectionString = ConfigurationManager.ConnectionStrings["KPortal"].ConnectionString;
        sqlDS.SelectCommand = "SELECT MaterialID AnswerID, MaterialName as Answer, ParentMaterialID as QuestionID FROM Materials WHERE ParentMaterialID = " + item.GetDataKeyValue("QuestionID").ToString();
     
        rblAnswer.DataSource = sqlDS;
     }
    }

  5. Answer
    Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 05 Dec 2011 Link to this post

    Hello Yuriy ,

    rblAnswer.DataSource = sqlDS;
    rblAnswer.Databind();

    if its not worked then please check how many records you get in sqlDS ???

    let me know if you have any concern.

    Thanks,
    Jayesh Goyani
  6. Yuriy
    Yuriy avatar
    13 posts
    Member since:
    Jul 2011

    Posted 05 Dec 2011 Link to this post

    Hi Jayesh,

    Works great and exactly as I expected. Thanks a lot for your help!

    Regards,
    Yuriy
  7. Milind
    Milind avatar
    16 posts
    Member since:
    Mar 2009

    Posted 21 Sep 2012 Link to this post

    Hi Yuriy,

    I am also trying to build a survey application. Your thread has helped a lot. A small question regarding the radgrid. When the grid is loaded is there any way to avoid clicking of edit button on a row. In other words the loaded grid is in edit mode by default so that the operator can save on some clicks and minutes.

    The application I am trying to develop is for call center, where in the caller will call on a number and while talking he/she is suppose to enter the details. There are 8 to 10 questions. I am able to get things going using radgrid. But the problem is, the caller is required to click on row's edit button to select the options as well as post the comments. For every row there needs to be a postback to save the data.

    I will be thankful if you could give me some clue on this front.

    Thanks again,

    Milind Shevade
  8. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 21 Sep 2012 Link to this post

    Hi,

    You can put all the items in edit mode on page load as shown below.
    C#:
    protected void Page_Load(object sender, EventArgs e)
    {
        for (int i = 0; i < RadGrid1.PageSize; i++)
        {
            RadGrid1.EditIndexes.Add(i);
        }
    }
    Note:Set AllowMultiRowEdit="true" for the RadGrid.

    Thanks,
    Shinu.
  9. Yuriy
    Yuriy avatar
    13 posts
    Member since:
    Jul 2011

    Posted 21 Sep 2012 Link to this post

    Hi Milind,

    In my application scenario I do not actually postback on every row change (my controls have autopostback=false). All options are clickable right after the page load (no edit mode), so the user can select the appropriate answers and once he/she is fine with the answers, click "submit" button to save all answers in one shot.  At that time I validate if all answers have been answered, build an XML doc and pass it to the database.

    See the code snippets below.

    Grid markup:
     
    <telerik:RadGrid ID="rgQuestionary" runat="server" CellSpacing="0" DataSourceID="sqlManufacturerSurvey"
     
    .....
              <Columns>
                  <telerik:GridBoundColumn DataField="Question" FilterControlAltText="Filter Question column"
                      HeaderText="Question" UniqueName="Question">
                  </telerik:GridBoundColumn>
                  <telerik:GridTemplateColumn FilterControlAltText="Filter column column" UniqueName="Answer"
                      HeaderText="Answer">
                      <ItemTemplate>
                          <asp:RadioButtonList ID="rblAnswer" runat="server" DataTextField="Answer" DataValueField="AnswerID"
                              RepeatLayout="Flow" BorderWidth="0">
                          </asp:RadioButtonList>
                      </ItemTemplate>
                  </telerik:GridTemplateColumn>
                  <telerik:GridBoundColumn DataField="QuestionID" FilterControlAltText="Filter QuestionID column"
                      HeaderText="QuestionID" UniqueName="QuestionID" Visible="False">
                  </telerik:GridBoundColumn>
              </Columns>

    ...

      </telerik:RadGrid>


    Code behind to commit all answers ("submit" button, outside of the grid):
    protected void RadButton1_Click(object sender, EventArgs e)
           {
               var sb = new StringBuilder();
     
               XmlWriter xw = XmlWriter.Create(sb);
     
               xw.WriteStartElement("ManufacturerProfile");
               xw.WriteAttributeString("SameSurchargeForAllServices", cbSurcharge.Checked.ToString());
                        
     
               foreach (GridDataItem item in rgServices.Items)
               {
                   CheckBox SelectedService = (CheckBox)item["SelectedService"].FindControl("cbSelectedService");
                   if (SelectedService.Checked)
                   {
                       xw.WriteStartElement("Service");
                       xw.WriteAttributeString("ServiceTypeID", item["ServiceTypeID"].Text.ToString());
                       xw.WriteEndElement();
                   }
               }
     
     
     
               bool res = true;
               foreach (GridDataItem item in rgQuestionary.Items)
               {
                   xw.WriteStartElement("Answer");
                   xw.WriteAttributeString("QuestionID", item["QuestionID"].Text.ToString());
                   RadioButtonList Answer = (RadioButtonList)item["Answer"].FindControl("rblAnswer");
                   xw.WriteAttributeString("AnswerID", Answer.SelectedValue.ToString());
                   xw.WriteEndElement();
                   if (Answer.SelectedValue.ToString() == "")
                   {
                       item["Question"].ForeColor = System.Drawing.Color.Red;
                       res = false;
                   }
                   else
                   {
                       item["Question"].ControlStyle.Reset();
                   }
               }
     
               if (res==false)
               {
                    
                   rnChangesSaved.Text = "Please answer all the questions";
                   rnChangesSaved.Show();
                   return;
               }
     
               xw.WriteEndDocument();
               xw.Flush();
               xw.Close();
               string FinalXML = sb.ToString().Substring(sb.ToString().IndexOf(">") + 1);
     
               string ConnString = ConfigurationManager.ConnectionStrings["KPortal"].ConnectionString;
               SqlConnection conn = new SqlConnection(ConnString);
               SqlCommand command = new SqlCommand("Exec SaveManufacturerProfile @QuestionaryResults = @QuestionaryResults, @LoginID = @LoginID", conn);
               command.Parameters.AddWithValue("QuestionaryResults", FinalXML);
               command.Parameters.AddWithValue("LoginID", Page.User.Identity.Name.ToString().ToLower());
               conn.Open();
               try
               {
                   command.ExecuteNonQuery();
               }
               finally
               {
                   conn.Close();
               }
                
                
               rnChangesSaved.Text = "Your company profile have been saved";
               rnChangesSaved.Show();
           }


    Hope this will help you.

    Regards,
    Yuriy
  10. Milind
    Milind avatar
    16 posts
    Member since:
    Mar 2009

    Posted 11 Oct 2012 Link to this post

    Hi Yuriy,

    Thanks for the reply. I am trying to go by your logic but am unable to get the changed values in the grid on server side after clicking Save button.

    Following is the aspx as well as aspx.cs script :

    ASPX:

    <%

     

    @ Page Title="Empulse HDFC - Call Transaction" Language="C#" MasterPageFile="~/EmpulseHDFC.Master" AutoEventWireup="true" CodeBehind="FrmCallTransaction.aspx.cs" Inherits="EmpulseHDFCv2.FrmCallTransaction" %>

     

    <%

     

    @ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>

     

    <

     

     

    asp:Content ID="Content2" ContentPlaceHolderID="MasterDetail" runat="server">

     

     

     

    <telerik:radinputmanager id="RadInputManager1" runat="server" Skin="Sunset">

     

     

     

    <telerik:TextBoxSetting BehaviorID="TextBoxBehavior1" InitializeOnClient="false" ErrorMessage="Invalid Data" Validation-IsRequired="true" >

     

     

     

    </telerik:TextBoxSetting>

     

     

     

    <telerik:RegExpTextBoxSetting BehaviorID="TextBoxBehavior2" ErrorMessage="Invalid Email" ValidationExpression="^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$" Validation-IsRequired="true">

     

     

     

    </telerik:RegExpTextBoxSetting>

     

     

     

    </telerik:radinputmanager>

     

     

     

    <telerik:RadAjaxManagerProxy id="RadAjaxManagerProxy1" runat="server">

     

     

     

    </telerik:RadAjaxManagerProxy>

     

     

     

    <br />

     

     

     

    <div id="divLeave" style="text-align:center; vertical-align:top;">

     

     

     

    <table runat="server" id="tbl2" width="100%">

     

     

     

    <tr>

     

     

     

    <td>

     

     

     

    <table runat="server" id="tbl3" width="100%" >

     

     

     

    <tr>

     

     

     

    <td style="text-align:left; vertical-align:middle; color:Black; font:Arial; font-size:small;width:10%">

     

     

     

    <asp:Literal ID="ltrCallType" Text="Select Call Type :" runat="server"></asp:Literal>

     

     

     

    </td>

     

     

     

    <td style="text-align:left; vertical-align:middle; color:Black; font:Arial; font-size:small;width:17%">

     

     

     

    <telerik:RadComboBox ID="ddlCallType" runat="server"

     

     

     

    DataTextField="vCallTypeName" DataValueField="nCallTypeId" EnableTextSelection="true"

     

     

     

    MarkFirstMatch="true"

     

     

     

    AutoPostBack="true" Sort="Ascending" Skin="Sunset"

     

     

     

    Font-Names="Arial" Font-Size="Small"

     

     

     

    onselectedindexchanged="OnDdlCallTypeSelectedIndexChanged" >

     

     

     

    </telerik:RadComboBox>

     

     

     

    </td>

     

     

     

    <td style="text-align:left; vertical-align:middle; color:Black; font:Arial; font-size:small;width:10%">

     

     

     

    <asp:Literal ID="ltrEmployeeName" Text="Select Employee :" runat="server"></asp:Literal>

     

     

     

    </td>

     

     

     

    <td style="text-align:left; vertical-align:middle; color:Black; font:Arial; font-size:small;width:30%">

     

     

     

    <telerik:RadComboBox ID="ddlEmployee" Runat="server" Skin="Sunset" Width="100%"

     

     

     

    DataTextField="vEmployeeName" DataValueField="vEmployeeId" EnableTextSelection="true"

     

     

     

    MarkFirstMatch="true" OnClientBlur="OnClientBlurValidateCombo"

     

     

     

    AutoPostBack="true" Sort="Ascending"

     

     

     

    HighlightTemplatedItems="true"

     

     

     

    style="overflow:hidden;"

     

     

     

    onselectedindexchanged="OnDdlEmployeeSelectedIndexChanged" >

     

     

     

    <ItemTemplate>

     

     

     

    <table style="width:325px">

     

     

     

    <tr>

     

     

     

    <td style="width:70%; text-align: left;">

     

    <%

     

    # DataBinder.Eval(Container.DataItem, "vEmployeeName")%>

     

     

     

    </td>

     

     

     

    <td style="width:30%; text-align: left;">

     

    <%

     

    # DataBinder.Eval(Container.DataItem, "vPhoneNo")%>

     

     

     

    </td>

     

     

     

    </tr>

     

     

     

    </table>

     

     

     

    </ItemTemplate>

     

     

     

    </telerik:RadComboBox>

     

     

     

    </td>

     

     

     

    <td style="text-align:left; vertical-align:middle; color:Black; font:Arial; font-size:small;width:5%">

     

     

     

    <asp:Literal ID="ltrCallComment" Text="Comments :" runat="server"></asp:Literal>

     

     

     

    </td>

     

     

     

    <td style="text-align:left; vertical-align:middle; color:Black; font:Arial; font-size:small;width:28%">

     

     

     

    <asp:TextBox ID="txtCallComment" runat="server" TextMode="MultiLine" Rows="2" onBlur="validateSpecialChars(this);"

     

     

     

    Width="99%" Font-Names="Arial" Font-Size="Small"></asp:TextBox>

     

     

     

    </td>

     

     

     

    </tr>

     

     

     

    <tr>

     

     

     

    <td style="text-align:left; vertical-align:middle; color:Black; font:Arial; font-size:small;width:10%">

     

     

     

    <asp:Literal ID="ltrCallStartDateTime" Text="Call Start DateTime :" runat="server"></asp:Literal>

     

     

     

    </td>

     

     

     

    <td style="text-align:left; vertical-align:middle; color:Black; font:Arial; font-size:small;width:17%">

     

     

     

    <telerik:RadDateTimePicker ID="dtpCallStart" Runat="server" Culture="en-US"

     

     

     

    Skin="Simple" Width="95%" >

     

     

     

    <TimeView ID="TimeView1" CellSpacing="-1" runat="server" EndTime="20:00:00" Interval="00:15:00" StartTime="08:00:00"></TimeView>

     

     

     

    <TimePopupButton ImageUrl="" HoverImageUrl=""></TimePopupButton>

     

     

     

    <Calendar ID="Calendar1" runat="server" UseRowHeadersAsSelectors="False" UseColumnHeadersAsSelectors="False" ViewSelectorText="x" Skin="Simple"></Calendar>

     

     

     

    <DateInput ID="DateInput1" runat="server" DisplayDateFormat="dd-MMM-yyyy HH:MM:ss" DateFormat="dd-MMM-yyyy HH:MM:ss" LabelWidth="40%"></DateInput>

     

     

     

    <DatePopupButton ImageUrl="" HoverImageUrl=""></DatePopupButton>

     

     

     

    </telerik:RadDateTimePicker>

     

     

     

    </td>

     

     

     

    <td style="text-align:left; vertical-align:middle; color:Black; font:Arial; font-size:small;width:10%">

     

     

     

    <asp:Literal ID="ltrCallEndDateTime" Text="Call End DateTime :" runat="server"></asp:Literal>

     

     

     

    </td>

     

     

     

    <td style="text-align:left; vertical-align:middle; color:Black; font:Arial; font-size:small;width:30%">

     

     

     

    <telerik:RadDateTimePicker ID="dtpCallEnd" Runat="server" Culture="en-US"

     

     

     

    Skin="Simple" Width="55%">

     

     

     

    <TimeView ID="TimeView2" CellSpacing="-1" runat="server" EndTime="20:00:00" Interval="00:15:00" StartTime="08:00:00"></TimeView>

     

     

     

    <TimePopupButton ImageUrl="" HoverImageUrl=""></TimePopupButton>

     

     

     

    <Calendar ID="Calendar2" runat="server" UseRowHeadersAsSelectors="False" UseColumnHeadersAsSelectors="False" ViewSelectorText="x" Skin="Simple"></Calendar>

     

     

     

    <DateInput ID="DateInput2" DisplayDateFormat="dd-MMM-yyyy HH:MM:ss" runat="server" DateFormat="dd-MMM-yyyy HH:MM:ss" LabelWidth="40%"></DateInput>

     

     

     

    <DatePopupButton ImageUrl="" HoverImageUrl=""></DatePopupButton>

     

     

     

    </telerik:RadDateTimePicker>

     

     

     

    </td>

     

     

     

    <td style="text-align:left; vertical-align:middle; color:Black; font:Arial; font-size:small;width:5%">

     

     

     

    &nbsp;

     

     

     

    </td>

     

     

     

    <td style="text-align:left; vertical-align:middle; color:Black; font:Arial; font-size:small;width:28%">

     

     

     

    &nbsp;

     

     

     

    </td>

     

     

     

    </tr>

     

     

     

    </table>

     

     

     

    </td>

     

     

     

    </tr>

     

     

     

    </table>

     

     

     

    <telerik:radgrid id="gvCallTransaction" runat="server"

     

     

     

    allowsorting="True" autogeneratecolumns="False" gridlines="None"

     

     

     

    CommandItemStyle-HorizontalAlign="Left" FilterItemStyle-HorizontalAlign="Left"

     

     

     

    showfooter="True" showstatusbar="True" Skin="Sunset"

     

     

     

    Width="100%" HorizontalAlign="Center" Height="420px"

     

     

     

    CellSpacing="0" onneeddatasource="OnGvCallTransactionNeedDataSource"

     

     

     

    onitemdatabound="OnGvCallTransactionItemDataBound" >

     

     

     

    <ClientSettings AllowDragToGroup="false" EnableRowHoverStyle="True">

     

     

     

    <Scrolling AllowScroll="True" UseStaticHeaders="True" />

     

     

     

    <Selecting AllowRowSelect="True" />

     

     

     

    <ClientEvents OnPopUpShowing="PopUpShowing" />

     

     

     

    </ClientSettings>

     

     

     

    <MasterTableView Name="tblCallTransaction" CommandItemDisplay="TopAndBottom" CommandItemStyle-Height="22px" CommandItemStyle-VerticalAlign="Middle" DataKeyNames="nQuestionId" >

     

     

     

    <CommandItemTemplate>

     

     

     

    <asp:LinkButton ID="lnkBtnSave" runat="server" Font-Names="Arial" Font-Size="small" ToolTip="Save Data" OnClick="LnkBtnSaveClick" AccessKey="S" >

     

     

     

    &nbsp;&nbsp;<img style="border:0px;vertical-align:middle;" alt="" src="Images/Save.png" /> Save </asp:LinkButton>

     

     

     

    </CommandItemTemplate>

     

     

     

    <Columns>

     

     

     

    <telerik:GridTemplateColumn UniqueName="TQuestion" HeaderText="Question">

     

     

     

    <ItemTemplate>

     

     

     

    <asp:Label ID="lblQuestion" runat="server" Text='<%# Bind("vQuestionDesc") %>'></asp:Label>

     

     

     

    </ItemTemplate>

     

     

     

    <ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="39%" Wrap="true" Font-Names="Arial" Font-Size="Small" />

     

     

     

    <HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="39%" />

     

     

     

    </telerik:GridTemplateColumn>

     

     

     

    <telerik:GridTemplateColumn UniqueName="TAnswer" HeaderText="Answer">

     

     

     

    <ItemTemplate>

     

     

     

    <asp:RadioButtonList ID="rblAnswer" runat="server" DataTextField="vAnswerDesc" DataValueField="nAnswerId" RepeatLayout="Flow" BorderWidth="0">

     

     

     

    </asp:RadioButtonList>

     

     

     

    </ItemTemplate>

     

     

     

    <ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="20%" Font-Names="Arial" Font-Size="Small" />

     

     

     

    <HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="20%" />

     

     

     

    </telerik:GridTemplateColumn>

     

     

     

    <telerik:GridTemplateColumn UniqueName="TComment" HeaderText="Comment">

     

     

     

    <ItemTemplate>

     

     

     

    <asp:TextBox ID="txtComment" runat="server" BorderStyle="None" BorderWidth="0px" AutoPostBack="false"

     

     

     

    Font-Names="Arial" Font-Size="Small" TextMode="MultiLine" Rows="6" Width="99%" onBlur="validateSpecialChars(this);"></asp:TextBox>

     

     

     

    </ItemTemplate>

     

     

     

    <ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="39%" Font-Names="Arial" Font-Size="Small" />

     

     

     

    <HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="39%" />

     

     

     

    </telerik:GridTemplateColumn>

     

     

     

    <telerik:GridTemplateColumn UniqueName="TQuestionId" HeaderText="" Visible="false">

     

     

     

    <ItemTemplate>

     

     

     

    <asp:Label ID="lblQuestionId" runat="server" Text='<%# Bind("nQuestionId") %>'></asp:Label>

     

     

     

    </ItemTemplate>

     

     

     

    <ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="0%" />

     

     

     

    <HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="0%" />

     

     

     

    </telerik:GridTemplateColumn>

     

     

     

    <telerik:GridTemplateColumn UniqueName="TCallTransactionId" HeaderText="" Visible="false">

     

     

     

    <ItemTemplate>

     

     

     

    <asp:Label ID="lblCallTransactionId" runat="server" Text='<%# Bind("nCallTransactionId") %>'></asp:Label>

     

     

     

    </ItemTemplate>

     

     

     

    <ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="0%" />

     

     

     

    <HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="0%" />

     

     

     

    </telerik:GridTemplateColumn>

     

     

     

    </Columns>

     

     

     

    </MasterTableView>

     

     

     

    <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Sunset"></HeaderContextMenu>

     

     

     

    </telerik:radgrid>

     

     

     

    </div>

     

    </

     

     

    asp:Content>

     



    ASPX.CS

    using

     

     

    System;

     

    using

     

     

    System.Collections.Generic;

     

    using

     

     

    System.Linq;

     

    using

     

     

    System.Web;

     

    using

     

     

    System.Web.UI;

     

    using

     

     

    System.Web.UI.WebControls;

     

    using

     

     

    Telerik.Web.UI;

     

    using

     

     

    System.Data;

     

    using

     

     

    System.Data.SqlClient;

     

    using

     

     

    MTIPLSQLCommonClass;

     

    using

     

     

    MTIPLSQLWebClass;

     

    using

     

     

    EmpulseHdfcClass;

     

    namespace

     

     

    EmpulseHDFCv2

     

    {

     

     

    public partial class FrmCallTransaction : System.Web.UI.Page

     

    {

     

     

    clsSQLCommonLib objSqlCommonLib = new clsSQLCommonLib();

     

     

     

    clsSQLWebFunctionLib objSqlWebFunctionLib = new clsSQLWebFunctionLib();

     

     

     

    clsCallTransaction objCallTransaction = new clsCallTransaction();

     

     

     

    string strQuery, strMsg;

     

     

     

    double dblAnswerId;

     

     

     

    protected void Page_Load(object sender, EventArgs e)

     

    {

     

     

    if (!IsPostBack)

     

    {

     

     

    ContentPlaceHolder mpContentPlaceHolder;

     

     

     

    Panel mpLoginPanel, mpWelcomePanel;

     

     

     

    RadContextMenu mpEmpulseHdfc;

     

     

     

    Label lbl1;

     

    mpContentPlaceHolder = (

     

    ContentPlaceHolder)Master.FindControl("MasterHeader");

     

     

     

    if (mpContentPlaceHolder != null)

     

    {

    mpLoginPanel = (

     

    Panel)mpContentPlaceHolder.FindControl("LoginPanel");

     

     

     

    if (mpLoginPanel != null)

     

    {

    mpLoginPanel.Visible =

     

    false;

     

    }

    mpWelcomePanel = (

     

    Panel)mpContentPlaceHolder.FindControl("WelcomePanel");

     

     

     

    if (mpWelcomePanel != null)

     

    {

    mpWelcomePanel.Visible =

     

    true;

     

    lbl1 = (

     

    Label)mpContentPlaceHolder.FindControl("Label3");

     

    lbl1.Text =

     

    "Welcome " + Session["strUserId"].ToString();

     

    }

    mpEmpulseHdfc = (

     

    RadContextMenu)mpContentPlaceHolder.FindControl("MnuEmpulseHdfc");

     

    mpEmpulseHdfc.Items.Clear();

    objSqlWebFunctionLib.PopulateRadContextMenu(

     

    ref mpEmpulseHdfc, "10");

     

    objSqlWebFunctionLib.BindTelerikDropDownIncludeSelect(

     

    "Select nCallTypeId, vCallTypeName from tblCallTypeMaster", ref ddlCallType);

     

    ddlCallType.SelectedIndex = ddlCallType.Items.IndexOf(ddlCallType.Items.FindItemByText(

     

    "- Select -"));

     

    objSqlWebFunctionLib.BindTelerikDropDownIncludeSelect(

     

    "Select nCallAllocationId, vEmployeeName, vPhoneNo,vEmployeeId from tblCallAllocation, tblCallTypeMaster where tblCallAllocation.nCallTypeId = tblCallTypeMaster.nCallTypeId and tblCallTypeMaster.nCallTypeId = '" + ddlCallType.SelectedValue + "' and vCallStatus = 'O' and vUserNTId = '" + Session["strUserId"].ToString() + "'", ref ddlEmployee);

     

    ddlEmployee.SelectedIndex = ddlEmployee.Items.IndexOf(ddlCallType.Items.FindItemByText(

     

    "- Select -"));

     

    dtpCallStart.SelectedDate =

     

    DateTime.Now;

     

    dtpCallEnd.SelectedDate =

     

    DateTime.Now;

     

    }

    }

    }

     

     

    protected void OnDdlCallTypeSelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)

     

    {

    objSqlWebFunctionLib.BindTelerikDropDownIncludeSelect(

     

    "Select nCallAllocationId, vEmployeeName, vPhoneNo,vEmployeeId from tblCallAllocation, tblCallTypeMaster where tblCallAllocation.nCallTypeId = tblCallTypeMaster.nCallTypeId and tblCallTypeMaster.nCallTypeId = '" + ddlCallType.SelectedValue + "' and vCallStatus = 'O' and vUserNTId = '" + Session["strUserId"].ToString() + "'", ref ddlEmployee);

     

    ddlEmployee.SelectedIndex = 0;

    }

     

     

    protected void OnDdlEmployeeSelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)

     

    {

    dtpCallStart.SelectedDate =

     

    DateTime.Now;

     

    dtpCallEnd.SelectedDate =

     

    DateTime.Now;

     

    gvCallTransaction.Rebind();

    }

     

     

    protected void OnGvCallTransactionNeedDataSource(object sender, GridNeedDataSourceEventArgs e)

     

    {

    strQuery =

     

    " SELECT 0 as nCallTransactionId, nQuestionId, vQuestionDesc FROM tblQuestionBankMaster where nCallTypeId = '" + ddlCallType.SelectedValue +"' and vActiveInactive = 'A' order by nDisplaySeqNo asc";

     

    gvCallTransaction.DataSource = objSqlCommonLib.ReturnDataTable(strQuery,

     

    "tblCallTransaction");

     

    }

     

     

    protected void OnGvCallTransactionItemDataBound(object sender, GridItemEventArgs e)

     

    {

     

     

    if (e.Item is GridDataItem)

     

    {

     

     

    GridDataItem item = (GridDataItem)e.Item;

     

     

     

    Label lblQuestionId = (Label)item.FindControl("lblQuestionId");

     

     

     

    Label lblCallTransactionId = (Label)item.FindControl("lblCallTransactionId");

     

     

     

    RadioButtonList rblAnswer = (RadioButtonList)item.FindControl("rblAnswer");

     

     

     

    TextBox txtBx = (TextBox)item.FindControl("txtComment");

     

    strQuery =

     

    "select vAnswerDesc, nAnswerId from tblAnswerBankMaster where nQuestionId = '" + lblQuestionId.Text + "'";

     

    objSqlWebFunctionLib.BindRadioButtonList(strQuery,

     

    ref rblAnswer);

     

    strQuery =

     

    "select nAnswerId from tblCallTransaction where nCallTypeId = '" + ddlCallType.SelectedValue + "' and vEmpTokenNo = '" + ddlEmployee.SelectedValue + "' and nQuestionId = '" + lblQuestionId.Text + "'";

     

    dblAnswerId =

     

    Convert.ToInt64(objSqlCommonLib.ReturnFieldData(strQuery, true));

     

    rblAnswer.SelectedIndex = rblAnswer.Items.IndexOf(rblAnswer.Items.FindByValue(

     

    Convert.ToString(dblAnswerId)));

     

    strQuery =

     

    "select vComment from tblCallTransaction where nCallTypeId = '" + ddlCallType.SelectedValue + "' and vEmpTokenNo = '" + ddlEmployee.SelectedValue + "' and nQuestionId = '" + lblQuestionId.Text + "'";

     

    txtBx.Text = objSqlCommonLib.ReturnFieldData(strQuery,

     

    true);

     

    strQuery =

     

    "select nCallTransactionId from tblCallTransaction where nCallTypeId = '" + ddlCallType.SelectedValue + "' and vEmpTokenNo = '" + ddlEmployee.SelectedValue + "' and nQuestionId = '" + lblQuestionId.Text + "'";

     

    lblCallTransactionId.Text = objSqlCommonLib.ReturnFieldData(strQuery,

     

    true);

     

    }

    }

     

     

    protected void LnkBtnSaveClick(object sender, EventArgs e)

     

    {

     

     

    RadAjaxManager objRadAjaxManager = RadAjaxManager.GetCurrent(this.Page);

     

     

     

    try

     

    {

     

     

    foreach (GridDataItem item in gvCallTransaction.Items)

     

    {

    objCallTransaction.nCallTransactionId =

     

    Convert.ToInt64(((Label)item.FindControl("lblCallTransactionId")).Text == "" ? "0" : ((Label)item.FindControl("lblCallTransactionId")).Text);

     

    objCallTransaction.vUserNTId = Session[

     

    "strUserId"].ToString();

     

    objCallTransaction.nCallTypeId =

     

    Convert.ToInt16(ddlCallType.SelectedValue);

     

    objCallTransaction.dtCallStartDate =

     

    Convert.ToDateTime(dtpCallStart.SelectedDate);

     

    objCallTransaction.dtCallEndDate =

     

    Convert.ToDateTime(dtpCallEnd.SelectedDate);

     

    objCallTransaction.vCallComment = txtCallComment.Text;

    objCallTransaction.vEmpTokenNo = ddlEmployee.SelectedValue;

    objCallTransaction.nQuestionId =

     

    Convert.ToInt64(((Label)item.FindControl("lblQuestionId")).Text == "" ? "0" : ((Label)item.FindControl("lblQuestionId")).Text);

     

    objCallTransaction.nAnswerId =

     

    Convert.ToInt64(((RadioButtonList)item.FindControl("rblAnswer")).SelectedValue);

     

    objCallTransaction.vComment = ((

     

    TextBox)item.FindControl("txtComment")).Text;

     

    strQuery =

     

    "select nScore from tblAnswerBankMaster where nQuestionId = '";

     

    strQuery = strQuery +

     

    Convert.ToInt64(((Label)item.FindControl("lblQuestionId")).Text == "" ? "0" : ((Label)item.FindControl("lblQuestionId")).Text) + "' and nAnswerId = '";

     

    strQuery = strQuery +

     

    Convert.ToInt64(((RadioButtonList)item.FindControl("rblAnswer")).SelectedValue) + "'";

     

    objCallTransaction.nScore =

     

    Convert.ToInt16(objSqlCommonLib.ReturnFieldData(strQuery, true));

     

    objCallTransaction.vOpenCloseTag =

     

    "O";

     

    }

    strMsg =

     

    "Data Saved";

     

    objRadAjaxManager.ResponseScripts.Add(

     

    "msg('" + strMsg + "');");

     

    }

     

     

    catch (Exception ex)

     

    {

    strMsg =

     

    "Error Occurred :\\n\\n" + objSqlCommonLib.EncodeJsString(ex.Message.ToString());

     

    objRadAjaxManager.ResponseScripts.Add(

     

    "msg('" + strMsg + "');");

     

    }

    }

    }

    }

    I will be thankful if you look into the code and suggest me some solution

    Thanks again,

    Milind

  11. Milind
    Milind avatar
    16 posts
    Member since:
    Mar 2009

    Posted 11 Oct 2012 Link to this post

    Hi Yuriy,

    Sorry to trouble you....

    For some reason my collogue had commented the insert/update statements in the stored proc that was getting executed in the backend. After removing it the data is getting saved. This is at the first round of testing. I do not think there will be any issue, else I might trouble you again. Thanks again... thanks a lot for your help.

    Warm regards,

    Milind
  12. Yuriy
    Yuriy avatar
    13 posts
    Member since:
    Jul 2011

    Posted 11 Oct 2012 Link to this post

    Hi Milind,

    I am glad it got resolved. You are welcomed to trouble this forum any time :).

    Cheers,
    Yuriy
  13. Balakrishna Reddy
    Balakrishna Reddy avatar
    37 posts
    Member since:
    Oct 2012

    Posted 28 Jan 2013 Link to this post

    Hi,
       i have radgrid with template column which have radio button list.
    i want to bind that radiobuttonlist dynamically.my code is like bellow,i am getting null when i am trying to find the control of radio button list.
    So please help in getting of this...

    <telerik:RadGrid ID="RadGrid_Machine" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                CellSpacing="0" GridLines="None" OnDeleteCommand="RadGrid_Machine_DeleteCommand"
                PageSize="5" OnInsertCommand="RadGrid_Machine_InsertCommand" OnItemCommand="RadGrid_Machine_ItemCommand"
                OnUpdateCommand="RadGrid_Machine_UpdateCommand"
                OnItemDataBound="RadGrid_Machine_ItemDataBound"
                onitemcreated="RadGrid_Machine_ItemCreated">
                <PagerStyle Mode="NextPrevAndNumeric" />
                <MasterTableView CommandItemDisplay="Top" EditMode="EditForms">
                    <Columns>
                        <telerik:GridEditCommandColumn FilterControlAltText="Filter EditCommandColumn column"
                            ButtonType="ImageButton">
                        </telerik:GridEditCommandColumn>
                        <telerik:GridBoundColumn DataField="MachineID" ReadOnly="true" HeaderText="MachineID"
                            UniqueName="MachineID">
                        </telerik:GridBoundColumn>
                        <telerik:GridDropDownColumn HeaderText="ProductType" DataField="ProductType" UniqueName="ProductType"
                            ListDataMember="ProductTypeMaster" ListTextField="ProductType">
                        </telerik:GridDropDownColumn>
                        <telerik:GridBoundColumn DataField="MachineName" FilterControlAltText="Filter column1 column"
                            HeaderText="MachineName" UniqueName="MachineName">
                        </telerik:GridBoundColumn>
    <telerik:GridDropDownColumn HeaderText="UnitType" DataField="UnitType" UniqueName="UnitType"
                            ListDataMember="UnitTypeMaster" ListTextField="UnitType">
                        </telerik:GridDropDownColumn>
                        <telerik:GridTemplateColumn HeaderText="PrintEdge">
                            <ItemTemplate>
                                <asp:RadioButtonList ID="rblList" runat="server" AutoPostBack="true" DataTextField="PrintEdge" RepeatColumns="3" DataValueField="PrintEdge" DataMember="MachineMaster" RepeatDirection="Horizontal">
                                    <asp:ListItem Text="Short" Value="0" Selected="True">a</asp:ListItem>
                                    <asp:ListItem Text="Long" Value="1">b</asp:ListItem>
                                    <asp:ListItem Text="Both" Value="2">c</asp:ListItem>
                                </asp:RadioButtonList>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridCheckBoxColumn FilterControlAltText="Filter IsActive column" UniqueName="IsActive"
                            DataField="IsActive" HeaderText="IsActive">
                        </telerik:GridCheckBoxColumn>
                        <telerik:GridButtonColumn FilterControlAltText="Filter column19 column" UniqueName="column19"
                            ButtonType="ImageButton" CommandName="Delete">
                        </telerik:GridButtonColumn>
                    </Columns>
                    <EditFormSettings>
                        <EditColumn ButtonType="ImageButton">
                        </EditColumn>
                    </EditFormSettings>
                </MasterTableView>
                <FilterMenu EnableImageSprites="False">
                </FilterMenu>
                <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
                </HeaderContextMenu>
                <ClientSettings>
                    <Scrolling AllowScroll="true" />
                </ClientSettings>
            </telerik:RadGrid>

    *******************************************************************************
    protected void RadGrid_Machine_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item.IsInEditMode)
            {
                GridEditableItem editItem = (GridEditableItem)e.Item;
                GridEditManager editMgr = (GridEditManager)editItem.EditManager;

                GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)editMgr.GetColumnEditor("ProductType");
                GridDropDownListColumnEditor editor1 = (GridDropDownListColumnEditor)editMgr.GetColumnEditor("UnitType");
                RadComboBox rcbProductType = editor.ComboBoxControl;
                RadComboBox rcbUnitType = editor1.ComboBoxControl;

                    DataTable dtProduct = objProductType.GetAllProductTypeMaster();
                    objProductType.FillFilteredRadComboList(rcbProductType, dtProduct);

                    rcbUnitType.Items.Clear();

                    RadioButtonList list = (RadioButtonList)editItem.FindControl("rblList");   //Here i am getting null
                    RadioButtonList rblAnswer = editItem.FindControl("rblList") as RadioButtonList;      //Here i am getting null
         
            }
        }
  14. Yuriy
    Yuriy avatar
    13 posts
    Member since:
    Jul 2011

    Posted 28 Jan 2013 Link to this post

    Hi,

    I am not sure what you are trying to do: are you trying to dynamically bind control in the edit mode? if this is the case, you will have to define the edit item  template for this column. Right now in your markup there is only item template:
    <telerik:GridTemplateColumn HeaderText="PrintEdge">
    //Ad this
      <EditItemTemplate>
       <asp:RadioButtonList ID="rblList" runat="server" AutoPostBack="true" DataTextField="PrintEdge" RepeatColumns="3" DataValueField="PrintEdge" DataMember="MachineMaster" RepeatDirection="Horizontal">
        <asp:ListItem Text="Short" Value="0" Selected="True">a</asp:ListItem>
        <asp:ListItem Text="Long" Value="1">b</asp:ListItem>
        <asp:ListItem Text="Both" Value="2">c</asp:ListItem>
        </asp:RadioButtonList>
     </EditItemTemplate>
     
      <ItemTemplate>
       <asp:RadioButtonList ID="rblList" runat="server" AutoPostBack="true" DataTextField="PrintEdge" RepeatColumns="3" DataValueField="PrintEdge" DataMember="MachineMaster" RepeatDirection="Horizontal">
        <asp:ListItem Text="Short" Value="0" Selected="True">a</asp:ListItem>
        <asp:ListItem Text="Long" Value="1">b</asp:ListItem>
        <asp:ListItem Text="Both" Value="2">c</asp:ListItem>
        </asp:RadioButtonList>
      </ItemTemplate>
    </telerik:GridTemplateColumn>

    If you want to bind in the normal mode then remove

    if (e.Item.IsInEditMode)

    and change the item type from GridEditableItem to GridDataItem.

    Regards,
    Yuiry
  15. Sushil
    Sushil avatar
    1 posts
    Member since:
    Apr 2015

    Posted 06 Apr 2015 Link to this post

    Hello SIr,

    Male/Female Is not inserting in the Database Table T17. Gender Column Shows vacant. Please Help me..

     

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017