Telerik Forums
UI for ASP.NET AJAX Forum
1 answer
724 views
Hi,

I am using RadGrid and want to make all rows editable on the initial load. I am setting all rows editable as shown below:

protected

 

void Grid_ItemCreated(object sender, GridItemEventArgs e) {

 

 

if (!IsPostBack && e.Item is GridDataItem) {

 

e.Item.Edit =

true;

 

}

}

But when ItemDataBound even is fired IsInEditMode property is still set to false. But Edit property is correctly set to true. In the RadGrid documentation says "We suggest using IsInEditMode instead of Edit to check whether an Item is in edit more or not.".  But the IsInEditMode property is set to false. Why is IsInEditMode property not set to true? I added my item data bound event handler below.

 

 

 

protected void Grid_ItemDataBound(object sender, GridItemEventArgs e) {

 

if

 

(e.Item is GridEditableItem && e.Item.IsInEditMode) { 
//--------------------------------------never getting to this block

 

 

DropDownList statusDropDown = editedItem.FindControl("StatusDropDown") as DropDownList;
//do something with statusDropDown

 

 

}
}

I tried changing my event handle to use Edit property instead, then the code is not finding control in the EditItemTemplate StatusDropDown DropDownList.

Here is my modified code and grid decleration:

protected void Grid_ItemDataBound(object sender, GridItemEventArgs e) {

 

if

 

(e.Item is GridEditableItem && e.Item.Edit) { 

 

 

  //------------------------------------------------I am geting null for statusDropDown

 

 

DropDownList statusDropDown= editedItem.FindControl("StatusDropDown") as DropDownList; 
//do something with statusDropDown

}
}

 

 

<telerik:RadGrid ID="Grid" runat="server" GridLines="None" AutoGenerateColumns="false"

                    OnItemDataBound="Grid_ItemDataBound" OnNeedDataSource="Grid_NeedDataSource"

                    OnItemCreated="Grid_ItemCreated" AllowMultiRowEdit="true">

                    <MasterTableView DataKeyNames="ClassId" EditMode="InPlace">

                        <Columns>

                           

                            <telerik:GridBoundColumn UniqueName="ClassName" HeaderText="Class Name" DataField="ClassId"

                                ReadOnly="true">

                            </telerik:GridBoundColumn>

                            <telerik:GridBoundColumn HeaderText="Site" DataField="SiteId" ReadOnly="true">

                            </telerik:GridBoundColumn>

                           

                            <telerik:GridTemplateColumn UniqueName="Status" HeaderText="Status">

                                <ItemTemplate>

                                    <asp:Label ID="statusLabel" runat="server">

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

                                    </asp:Label>

                                </ItemTemplate>

                                <EditItemTemplate>

                                    <asp:DropDownList ID="StatusDropDown" runat="server" />

                                </EditItemTemplate>

                            </telerik:GridTemplateColumn>                           

                        </Columns>

                    </MasterTableView>

</telerik:RadGrid>

I am trying to avoid using prerenderer becasue of rebind call.

Anyone has any idea what I am missing. Please let me know if you see a better way to do this. I appreciate any help.

Thanks,
Ana


 

 

 

Shinu
Top achievements
Rank 2
 answered on 18 Oct 2011
1 answer
131 views
I'm writing to ask how best to maintain the Empty Message value in a RadComboBox - after the selection of a RadComboBoxItem;



<
telerik:RadComboBox ID="RadComboBox1" runat="server" Skin="Black"
                    AutoPostBack="True"
                    onselectedindexchanged="RadComboBox1_SelectedIndexChanged"
                    Font-Names="Microsoft Sans Serif" Width="160px"
                    EmptyMessage="Maines Paper" MarkFirstMatch="True">
                    <Items>                        
                        <telerik:RadComboBoxItem runat="server" Text="Sign out" Value="Sign out" />
                        <telerik:RadComboBoxItem runat="server" Text="Change Password" Value="Change Password" />
                    </Items>
                </telerik:RadComboBox>
Princy
Top achievements
Rank 2
 answered on 18 Oct 2011
8 answers
473 views
I'm not sure if i can accomplish this is a radconfirm or radalert. But this my scenario;

You can make an enquiry on an item. But to do so you must be logged in. So what i'm doing at the moment is using javascripts alert to popup a message saying, "You need to be registered click 'ok' here to register, or 'cancel' to cancel...".

However i'd like to have 'Click here to register, or click here to login, or click here to cancel'. Is this possible with either of these or will i have to use an actual radwindow ?

Alan
Stuart Hemming
Top achievements
Rank 2
 answered on 17 Oct 2011
9 answers
409 views
I'm trying to use the RadUpload control inside of a JQuery dialog in a ASP.Net page.  I'm having a problem with the RadUpload complaining that it's not inside of a form.  The message I get is "RadUpload requires to be in a form tag to operate properly!".

The behavior of JQuery is to take any html component it wraps in a dialog and to move it out to just before the end of the body element (this is done because some browsers have trouble rendering items in absolute coordinates, when they are in other html containers).  This causes that part of the html to go outside of the ASP.Net form.  So now the RadUpload is outside of the form...

In the dialog's ok button, I move the dialog contents back inside the form, just before submitting the form.  This moves all the items back to the form and submits them correctly.  This all works except for that annoying message I get from the RadUpload every time the page runs.  Is there a way to turn off this message, and tell the RadUpload that I know what I'm doing, and it should stop complaining?

Thanks

Andy
Mario
Top achievements
Rank 1
 answered on 17 Oct 2011
2 answers
365 views
I followed the example in "RadComboBox in RadGrid", the ItemsRequested event is not firing. attached the code. Please help me, is there any mistake in the code.  
Thanks,
<telerik:RadGrid ID="RadGrid2" GridLines="None" AutoGenerateColumns="false" PageSize="7" AllowPaging="true" AllowSorting="true"
                runat="server" OnItemDataBound="OnItemDataBoundHandler" DataSourceID="ProductsDataSource" AllowAutomaticUpdates="true"
                AllowAutomaticInserts="True" ShowStatusBar="true" Skin="Office2010Blue">
                <MasterTableView ShowFooter="false" DataKeyNames="inventoryid" EditMode="InPlace" CommandItemDisplay="TopAndBottom">
                <Columns>
 
                     
                    <telerik:GridTemplateColumn UniqueName="conditioncode" HeaderText="<%$ Resources:locStrings, GV_COL_PO_ConditionCode %>" SortExpression="conditioncode" ItemStyle-Width="150px">
                    <FooterTemplate> Template footer</FooterTemplate>
                    <FooterStyle VerticalAlign="Middle" HorizontalAlign="Center" />
                    <ItemTemplate>
                        <%#DataBinder.Eval(Container.DataItem, "conditioncode")%>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadComboBox runat="server" ID="RadComboBox1" EnableLoadOnDemand="True" DataTextField="code" DataValueField="conditionid"
                                AutoPostBack="true" HighlightTemplatedItems="true" Height="140px" Width="150px" DropDownWidth="200px"
                                OnItemsRequested="RadComboBox1_ItemsRequested"
                                OnSelectedIndexChanged="OnSelectedIndexChangedHandler" >
                                <HeaderTemplate>
                                    <ul>
                                    <li class="col1">Code</li>
                                    <li class="col2">Condition</li>
                                    </ul>
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <ul>
                                    <li class="col1">
                                        <%# DataBinder.Eval(Container,"Text")%>
                                    </li>
                                    <li class="col2">
                                        <%# DataBinder.Eval(Container,"Attributes['code']")%></li>
                                    </ul>
                                </ItemTemplate>
                        </telerik:RadComboBox>
                    </EditItemTemplate>
                    </telerik:GridTemplateColumn>
 
 
                    <telerik:GridEditCommandColumn FooterText="EditCommand footer" UniqueName="EditCommandColumn" HeaderText="Edit" UpdateText="Update"
                                                    HeaderStyle-Width="100px">
                    </telerik:GridEditCommandColumn>
 
                </Columns>
                </MasterTableView>
            </telerik:RadGrid>
 
            <asp:SqlDataSource ID="ProductsDataSource" runat="server" ConnectionString="Data Source=VSSCLOUDAPP1;Initial Catalog=iqrtest_20113108;User ID=sa; Password=admin!23"
                SelectCommand="SELECT ptid, inventoryid, unitcost, conditioncode, status, receivestatus, mfgr
                                FROM inventory WHERE ptid=501">
 
            </asp:SqlDataSource>
 
C#:
 
protected void OnItemDataBoundHandler(object sender, GridItemEventArgs e)
        {
            if (e.Item.IsInEditMode)
            {
                GridEditableItem item = (GridEditableItem)e.Item;
                if (!(e.Item is IGridInsertItem))
                {
                    RadComboBox combo = (RadComboBox)item.FindControl("RadComboBox1");
                    RadComboBoxItem selectedItem = new RadComboBoxItem();
                    selectedItem.Value = ((DataRowView)e.Item.DataItem)["conditionid"].ToString();
                    selectedItem.Text = ((DataRowView)e.Item.DataItem)["code"].ToString();
                    selectedItem.Attributes.Add("condition", ((DataRowView)e.Item.DataItem)["condition"].ToString());
                    combo.Items.Add(selectedItem);
                    selectedItem.DataBind();
                    Session["conditionid"] = selectedItem.Value;
                }
            }
        }
 
        protected void RadComboBox1_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
        {
 
            DataTable dt = new DataTable();
            dt = IQR.Generic.cGeneric.GetData(cStoredProcedureConstants.SP_POItem_GetConditionCodes, true);
 
            RadComboBox rcbConditionCode = (RadComboBox)sender;    // Clear the default Item that has been re-created from ViewState at this point.    comboBox.Items.Clear();
            foreach (DataRow row in dt.Rows)
            {
                RadComboBoxItem item = new RadComboBoxItem();
                item.Value = row["conditionid"].ToString();
                item.Text = row["code"].ToString();
                item.Attributes.Add("condition", row["condition"].ToString());
                rcbConditionCode.Items.Add(item);
                item.DataBind();
            }
 
        }
 
        protected void OnSelectedIndexChangedHandler(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            Session["conditionid"] = e.Value;
        }

Muthu

Elliott
Top achievements
Rank 2
 answered on 17 Oct 2011
3 answers
199 views
     Hello.
I`m using RadGrid with SqlDataSource. Filter in RadGrid work fine except using such words as "AND", "OR" in filter expression (for example "mike and smith"). In this situation filter is reseting and grid not filtered.
I didn`t find any post with this question.
Any ideas?
Elliott
Top achievements
Rank 2
 answered on 17 Oct 2011
5 answers
179 views
Hello,

is it possible top open the calender on pressing function key F4 when cursor is in DateInput field of the RadDatePicker control?
I've tried to catch the key pres with ClientEvent OnKeyPress but this doesn't catch pressig F4.

Can someone help me?

Regards,
  Jos Meerkerk
RvdGrint
Top achievements
Rank 1
 answered on 17 Oct 2011
3 answers
395 views
This seems like pretty common functionality, so I'm hoping that there is a simple answer, but I've tried a hundred different ways.  Basically, I have a RadGrid that contains an editable checkbox field.  This field is populated based on a boolean database field (using information gained from this link, I was able to get this to display properly).  This field is editable, and when in edit mode, I am able to check the box.  However, when I click "Update", the ItemDataBound event fires again and resets the checkbox item to the value in the database.  I have tried to combine this with the method I found here  to determine if the Item is InEditMode and skip the "set the checkbox value" part of the code, but this process hits the "else" part of the script first (resetting the value to the database value).  I'd certainly appreciate any guidance!  

Here is my aspx code:

<telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" AllowSorting="True"
    AllowAutomaticDeletes="true" AllowPaging="True" PageSize="20" runat="server"
    GridLines="None" Width="95%" AllowAutomaticUpdates="true" OnItemDataBound="RadGrid1_ItemDataBound"
    AllowMultiRowEdit="true" OnItemUpdate="RadGrid1_ItemUpdated" OnItemDeleted="RadGrid1_ItemDeleted"
    OnItemInserted="RadGrid1_ItemInserted">
    <MasterTableView Width="100%" CommandItemDisplay="Top" HorizontalAlign="NotSet" AutoGenerateColumns="false">
        <Columns>
            <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
                <ItemStyle CssClass="MyImageButton" />
            </telerik:GridEditCommandColumn>
            <telerik:GridButtonColumn ConfirmText="Remove this subscription?" ConfirmDialogType="RadWindow"
                ConfirmTitle="Unsubscribe" ButtonType="ImageButton" CommandName="Delete" Text="Unsubscribe"
                UniqueName="DeleteColumn">
                <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />
            </telerik:GridButtonColumn>
                            <telerik:GridCheckBoxColumn HeaderText="Subscribed" UniqueName="Subscribed" />
            <telerik:GridDropDownColumn DataField="SubscriptionId" DataSourceID="SqlDataSource1"
                HeaderText="Subscription" ListTextField="SubscriptionName" ListValueField="SubscriptionId"
                UniqueName="SubscriptionId" ColumnEditorID="GridDropDownColumnEditor1" ReadOnly="true">
            </telerik:GridDropDownColumn>
            <telerik:GridBoundColumn DataField="SubscriptionDescription" HeaderText="SubscriptionDescription"
                UniqueName="SubscriptionDescription" ReadOnly="true">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="TargetAudience" HeaderText="TargetAudience" UniqueName="TargetAudience"
                ReadOnly="true">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="DateAdded" HeaderText="DateAdded" UniqueName="DateAdded"
                ColumnEditorID="GridTextBoxColumnEditor1" ReadOnly="true">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="DateRemoved" HeaderText="DateRemoved" UniqueName="DateRemoved"
                ColumnEditorID="GridTextBoxColumnEditor1" ReadOnly="true">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Feedback" HeaderText="Feedback" UniqueName="Feedback"
                ColumnEditorID="GridTextBoxColumnEditor1">
            </telerik:GridBoundColumn>
        </Columns>
        <PagerStyle Mode="NextPrevNumericAndAdvanced" />
    </MasterTableView>
</telerik:RadGrid>

and here is the ItemDataBound segment of my code behind page where I attempted to combine the two methods above:

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
            {
                if (e.Item.OwnerTableView.IsItemInserted)
                {
                    //item is about to be inserted
                }
                else
                {
                    //item is about to be updated
                }
            }
            else
            {
          
//need to find a way to skip this if we are in Edit mode, as this resets any saved data to the db values
if (e.Item is GridDataItem)
                {
                    GridDataItem item = (GridDataItem)e.Item;
                    DataRowView row = (DataRowView)item.DataItem;
                    CheckBox chk = (CheckBox)item["Subscribed"].Controls[0];
                    string value = row["Subscribed"].ToString();
 
                    if (value == "Yes" || (value == "1"))
                        chk.Checked = true;
                    else
                        chk.Checked = false;
                }
            }
        }
Jayesh Goyani
Top achievements
Rank 2
 answered on 17 Oct 2011
1 answer
182 views
In an ajaxified RadGrid, I want two buttons to cause a post back (bypass Ajax) and execute some back-end code. Here's what I have so far...

Buttons (just showing one for simplicity):
<telerik:GridTemplateColumn HeaderText="Actions">  
    <ItemTemplate>
        <asp:ImageButton ID="btnEdit" runat="server" OnClientClick="realPostBack();"  ImageUrl="~/images/icon_edit.png" style="display: inline-block" ToolTip="Edit" CommandName="fbEdit"  />
    </ItemTemplate>
</telerik:GridTemplateColumn>

Javascript function I'm using to disable the postback:
<script type="text/javascript">
  function realPostBack(eventTarget, eventArgument) {
    $find("<%= RadAjaxPanel1.ClientID %>").__doPostBack(eventTarget, eventArgument);
  }
</script>

Code-behind I want to execute:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
 {
   if (e.CommandName == "fbEdit")
      {
        //grab variables from row's cells
       string userID = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["UserID"];
       string userName= e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["UserName"];
       string userEmail = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["UserEmail"];
 
       //DO SOME PROCESSING STUFF
 
      }
   if(e.CommandName == "fbDelete")
    {
       //delete record
     }
 }

So the post back does indeed occur, but my code never fires. I'm guessing it's because the event is tied to the grid and not to buttons im "un-ajaxifying", but I went this way because I NEED to capture the values of some of the cells in the row that the button was clicked.

Maybe I can rework this to use the buttons onClick Event, but I would still need to capture those values.

Can anyone help?
Jayesh Goyani
Top achievements
Rank 2
 answered on 17 Oct 2011
1 answer
306 views
I have two listboxes on a form. One is populated using a SQLDataSource and the other is populated using a StoredProc.

<telerik:RadListBox ID="rlb_ADGroups" runat="server" CheckBoxes="True" 
DataKeyField="GroupName" DataSourceID="sds_ADGroups" DataTextField="GroupName" 
DataValueField="GroupName" Height="200px" Width="400px">
</telerik:RadListBox>
  
<asp:SqlDataSource ID="sds_ADGroups" runat="server"
ConnectionString="<%$ ConnectionStrings:IT_CentralConnectionString %>"       
SelectCommand="SELECT [GroupName], [ADsPath] FROM [vw_AD_ADSI_Groups] ORDER BY [GroupName]">
</asp:SqlDataSource>
  
  
  
  
<telerik:RadListBox ID="rlb_MemberGroups" runat="server" CheckBoxes="True" 
DataKeyField="groupName" DataTextField="groupName"
DataValueField="groupName" Height="200px" Width="400px">
</telerik:RadListBox>

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
  
        rlb_MemberGroups.DataSource = GetGroups()
        rlb_MemberGroups.DataBind()
  
    End Sub
  
  
    Private Function GetGroups() As DataTable
  
        'Dim UserName As String = Request.QueryString("UserName")
        Dim UserName As String = "abrowning"
  
        Dim connectionString As String = DirectCast(ConfigurationManager.ConnectionStrings("IT_CentralConnectionString").ConnectionString, String)
        Dim connection As New SqlConnection(connectionString)
        Dim command As New SqlCommand(connectionString, connection)
  
        command = New SqlCommand("procGetGroupUsers", connection)
        command.CommandType = CommandType.StoredProcedure
  
        command.Parameters.Add("@UserName", SqlDbType.VarChar).Value = UserName
  
        command.Connection.Open()
  
        Dim myDataAdapter As New SqlDataAdapter(command)
        Dim myDataSet As New DataSet
        Dim dtData As New DataTable
        myDataAdapter.Fill(myDataSet)
        Return myDataSet.Tables(0)
  
        command.Connection.Close()
  
    End Function


I want to be able to add and remove a user to and from AD groups. When I add a user to groups and obtain the data from the List Box populated from the SQLDataSource, the user is added to the groups. I also know the values are pulling from the listbox because I place the values in a label so I can see them. (For testing). Here is the code for adding the user to the groups:

Protected Sub btn_AddToGroup_Click(sender As Object, e As System.EventArgs) Handles btn_AddToGroup.Click
    Dim UserName As String = "abrowning"
    For Each item As RadListBoxItem In rlb_ADGroups.CheckedItems
        Dim ADGroup As String = item.Value.ToString()
        Label1.Text = ADGroup
        Using context = New PrincipalContext(ContextType.Domain, "tustin_nt")
            Dim group As GroupPrincipal = GroupPrincipal.FindByIdentity(context, ADGroup)
            If group IsNot Nothing Then
                Using user = UserPrincipal.FindByIdentity(context, IdentityType.Name, UserName)
                    If UserName IsNot Nothing Then
                        group.Members.Add(context, IdentityType.UserPrincipalName, UserName + "@tusd.local")
                        group.Save()
                    End If
                End Using
            End If
        End Using
    Next
End Sub

However, when I attempt the same process to remove a user, I am unable to obtain the values from the List Box that was populated using the StoredProc. I can tell no values are being obtained becasue the Label I attempt to populate stays empty. Here is my code to remove the user from groups:

Protected Sub btn_RemoveFromGroup_Click(sender As Object, e As System.EventArgs) Handles btn_RemoveFromGroup.Click
       Dim username As String = "abrowning"
       For Each item As RadListBoxItem In rlb_MemberGroups.CheckedItems
           Dim ADGroup As String = item.Value.ToString()
           Label2.Text = ADGroup
           Using context = New PrincipalContext(ContextType.Domain, "TUSTIN_NT")
               Dim group As GroupPrincipal = GroupPrincipal.FindByIdentity(context, ADGroup)
               If group IsNot Nothing Then
                   Using user = UserPrincipal.FindByIdentity(context, IdentityType.Name, username)
                       If username IsNot Nothing Then
                           group.Members.Remove(context, IdentityType.UserPrincipalName, username + "@tusd.local")
                           group.Save()
                       End If
                   End Using
               End If
           End Using
       Next
   End Sub


I have set the DataKeyField, DataTextField, and the DataValueField in the rlb_MemberGroups List Box.

Can someone please help explain why I am unable to retrieve the Checked value from one List Box but not the other?

Thank you in advance.


Allan
Top achievements
Rank 2
 answered on 17 Oct 2011
Narrow your results
Selected tags
Tags
+? more
Top users last month
Grant
Top achievements
Rank 3
Iron
Iron
Iron
Dean
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Emil
Top achievements
Rank 1
Iron
Robert
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Top users last month
Grant
Top achievements
Rank 3
Iron
Iron
Iron
Dean
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Emil
Top achievements
Rank 1
Iron
Robert
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?