Telerik Forums
UI for ASP.NET AJAX Forum
1 answer
97 views
Hello,

I'm trying to move the page of my grid when my page loads. At the moment I'm able to load the correspondent data to the page I want to move, however the pagination control remains always in the page number one.

Any help?

Thanks
Amaro Barros
Princy
Top achievements
Rank 2
 answered on 19 Sep 2011
0 answers
158 views
This gave me fits, perhaps it can be useful to someone else.

The problem was that I have one page where the user can select from a drop down to edit one of a number of different reference tables in the grid.  They select a table, and the datasource and grid are rebound to that particular table.

Part of the problem then is limiting their input to the proper length for each field.

Unfortunately the sqldatasource doesn't preserve the underlying SQL types, at least not that I could find.  It converts varchars to a "string" type.  So there is no field length available.

So we retrieve the schema data separately from the DB.  Where lstReference is the list box they select the table to edit from, and the value contains the table name.  Note that it's only getting the length for the varchar and nvarchar fields.  Those are the only ones I'm interested in here, but you could certainly modify that to your needs.
private void GetSchema()
{
    // Clear the list out.
    _charFieldLength.Clear();
    DataTable dt = new DataTable();
    string connString = Util.GetConnectionString();
    SqlConnection conn = new SqlConnection(connString);
    conn.Open();
      
    try
    {
        // Retrieve the schema info from the DB.
        string[] restriction = { Util.GetDBName(), null, lstReference.Items[lstReference.SelectedIndex].Value, null };
        dt = conn.GetSchema("Columns", restriction);
    }
    catch (Exception ex)
    {
        // Log error
    }
    finally
    {
        if (conn.State == ConnectionState.Open)
            conn.Close();
    }
    // Populate the list with the schema info we're interested in.
    foreach (DataRow row in dt.Rows)
    {
        if (row["DATA_TYPE"].ToString() == "varchar" || row["DATA_TYPE"].ToString() == "nvarchar")
        {
            FieldInfo fi = new FieldInfo();
            fi.FieldName = row["COLUMN_NAME"].ToString();
            fi.DataLength = int.Parse(row["CHARACTER_MAXIMUM_LENGTH"].ToString());
            _charFieldLength.Add(fi);
        }
    }
}


And we can store that information in a list of these structs, just the field name and length.
private struct FieldInfo
{
    public string FieldName;
    public int DataLength;
    public FieldInfo(string fieldName, int dataLength)
    {
        FieldName = fieldName;
        DataLength = dataLength;
    }
}
List<FieldInfo> _charFieldLength = new List<FieldInfo>();


And this took me a while to weed out, but I did find a Telerik example that I was able to finally use to get a reference to the auto generated edit text boxes to be able to actually set the MaxLength.  This works for both Edit and Insert.
protected void gridActivity_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditableItem form = (GridEditableItem)e.Item;
        for (int i = 0; i < _charFieldLength.Count; i++)
        {
            TextBox dataField = (TextBox)form[_charFieldLength[i].FieldName].Controls[0];
            dataField.MaxLength = _charFieldLength[i].DataLength;
        }
    }
}
Marbry
Top achievements
Rank 1
 asked on 19 Sep 2011
1 answer
102 views
I am not sure if that will be the right place to ask.
I am writing a asp.net composite server control, which will have a RadGrid as part of it. I don't want to expose the whole grid as a public property though, instead I would like to expose just GridColumnCollection part. 

GridColumnsCollection is a read-only property though so I can't write the code below:
[
    Category("Grid"),
    Description("Columns for a grid."),
    DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
    PersistenceMode(PersistenceMode.InnerProperty)
]
public GridColumnCollection GridColumns
{
    get
    {
        EnsureChildControls();
        return grid.MasterTableView.Columns;
    }
    set
    {
        EnsureChildControls();
        grid.MasterTableView.Columns = value;
    }
}

When I am trying to change it to something like the code below, I will get an error saying that GridColumnCollection does not have constructor which takes 0 arguments.
    Category("Grid"), 
    Description("Columns for a grid."), 
    DesignerSerializationVisibility(DesignerSerializationVisibility.Content), 
    PersistenceMode(PersistenceMode.InnerProperty) 
public GridColumnCollection GridColumns 
    get 
    
        EnsureChildControls(); 
        return grid.MasterTableView.Columns; 
    
    set 
    
        EnsureChildControls(); 
        foreach(GridColumn col in value)
        {
                 grid.MasterTableView.Columns.Add(col); 
        }
    
}

Is there any way to expose just columns from RadGrid as a property of a composite server control?

Thanks,

Daniel
Daniel
Top achievements
Rank 1
 answered on 19 Sep 2011
3 answers
746 views
Hi,
I explain my situation.
I have a grid with many template columns.
One template column (uniquename: "ValoreTextBoxComboBox")  has two controls  a label ("LabelDescrizioneI") binded and a radcombobox ("RadComboBoxValore") not binded. 
Then programmatically  "OnItemDatabound " event  of the radgrid i decided which control is visible and in case this control is the radcombobox i bind it.
Everything works until i click "Edit" on the radgrid, the combobox lost everithing ( data and selectedvalue) .

<telerik:RadGrid ID="rdgParamDatiAziendali" AllowPaging="true" DataSourceID="edsGridParam" runat="server" OnUpdateCommand="rdgParamDatiAziendalie_UpdateCommand"
           GridLines="None" Width="97%" AllowSorting="true" PageSize="20" OnItemDataBound ="rdgParamDatiAziendali_ItemDataBound">    
        <MasterTableView AutoGenerateColumns="False" EditMode="InPlace" DataKeyNames="IdConfigurazioneProgrammaCultura"
           OverrideDataSourceControlSorting="true" TableLayout="Auto">
           <CommandItemTemplate>
           </CommandItemTemplate>
                                                                                                                                                                                                                                                                                           <Columns
          <telerik:GridEditCommandColumn ButtonType="ImageButton" CancelImageUrl="~/Images/ImagesGrid/Cancel.gif"
               EditImageUrl="~/Images/ImagesGrid/Edit.gif" UpdateImageUrl="~/Images/ImagesGrid/Update.gif"
               InsertImageUrl="~/Images/ImagesGrid/Update.gif" UniqueName="EditCommandColumn"
               ItemStyle-Width="50px" HeaderStyle-Width="50px" />
           <telerik:GridBoundColumn DataField="IdCultura" DataType="System.Int64" HeaderText="IdCultura"
               SortExpression="IdCultura" UniqueName="IdCultura" ReadOnly="true" Visible="false">
           </telerik:GridBoundColumn>
           <telerik:GridBoundColumn DataField="IdConfigurazioneProgrammaCultura" DataType="System.Int64" HeaderText="Id" SortExpression="IdConfigurazioneProgrammaCultura"
               UniqueName="IdConfigurazioneProgrammaCultura" Display="false">
           </telerik:GridBoundColumn>                       
            <telerik:GridBoundColumn DataField="Descrizione" DataType="System.String" HeaderText="Descrizione" SortExpression="Descrizione"
               UniqueName="Descrizione"  ReadOnly="true" HeaderStyle-Width="405px" ItemStyle-Height="13px"
           </telerik:GridBoundColumn>
           <mwc:GridBoundColumn DataField="Id" DataType="System.Int64" HeaderText="Id" SortExpression="Id"
               UniqueName="Id" Display="false"></mwc:GridBoundColumn
                <mwc:GridBoundColumn DataField="IdParametroAzienda" DataType="System.Int64" HeaderText="IdParametroAzienda" SortExpression="IdParametroAzienda"
               UniqueName="IdParametroAzienda" Display="false">
           </mwc:GridBoundColumn>
              <telerik:GridTemplateColumn Resizable="true" HeaderStyle-Width="275px" UniqueName="ValoreTextBoxComboBox"
                   SortExpression="ValoreTextBoxComboBox" ItemStyle-Height="13px">
                   <HeaderTemplate>
                       <mwc:Label ID="LabelUnificata" runat="server" LabelResources="valore_simi"
                           ParentType="RadGrid" Height="13px"></mwc:Label>
                   </HeaderTemplate>
                   <ItemTemplate>
                       <mwc:Label ID="LabelDescrizioneI" runat="server" Text='<%# Bind("DescrizioneTextBox") %> '
                           Width="270px" ReadOnly="true" ParentType="RadGrid" Height="13px"></mwc:Label>
                       <telerik:RadComboBox ID="RadComboBoxValore" runat="server" Width="270px" AutoPostBack="false"
                           ParentType="RadGrid" ReadOnly="true" Height="13px">
                       </telerik:RadComboBox>
                       <mwc:HiddenField ID="HiddenFieldQueryRiga" runat="server" Value='<%# Bind("QueryComboBox") %>' />
                       <mwc:HiddenField ID="HiddenFieldTipoControllo" runat="server" Value='<%# Bind("IdTipoParametro") %>' />
                       <mwc:HiddenField ID="HiddenFieldSelectedValueRadComboBoxValore" runat="server" Value='<%# Bind("ValoreComboBox") %>' />
                   </ItemTemplate>
                   <EditItemTemplate>
                       <mwc:TextBox ID="TextBoxDescrizione" runat="server" Width="300px" Text='<%# Bind("DescrizioneTextBox") %>'></mwc:TextBox>
                       <telerik:RadComboBox ID="RadComboBoxValore" runat="server" Width="300px" AutoPostBack="false">
                       </telerik:RadComboBox>
                       <mwc:HiddenField ID="HiddenFieldQueryRiga" runat="server" Value='<%# Bind("QueryComboBox") %>' />
                       <mwc:HiddenField ID="HiddenFieldTipoControllo" runat="server" Value='<%# Bind("IdTipoParametro") %>' />
                       <mwc:HiddenField ID="HiddenFieldSelectedValueRadComboBoxValore" runat="server" Value='<%# Bind("ValoreComboBox") %>' />
                   </EditItemTemplate>
               </telerik:GridTemplateColumn>
               <mwc:GridTemplateColumn Resizable="false" HeaderStyle-Width="60px" UniqueName="Abilitato"
                   ItemStyle-Height="13px">
                   <HeaderTemplate>
                       <mwc:Label ID="LabelAbilitato" runat="server" LabelResources="abilitato_simi"
                           ParentType="RadGrid" Width="60px" Height="13px"></mwc:Label>
                   </HeaderTemplate>
                   <ItemTemplate>
                       <div style="text-align: center;">
                           <mwc:CheckBox ID="CheckBoxAbilitatoI" runat="server" Checked='<%# Bind("Abilitato") %>'
                               Enabled="false" Width="55px" Height="13px" />
                       </div>
                   </ItemTemplate>
                   <EditItemTemplate>
                       <mwc:CheckBox ID="CheckBoxAbilitatoE" runat="server" Checked='<%# Bind("Abilitato") %>'
                           Width="55px" Height="13px" />
                   </EditItemTemplate>
               </mwc:GridTemplateColumn>
       </Columns
       </MasterTableView
       </telerik:RadGrid>

The c# code:
protected void rdgParamDatiAziendali_ItemDataBound(object source, GridItemEventArgs e)
   {
       GridDataItem dataBoundItem = e.Item as GridDataItem;
       if (!(e.Item is GridDataInsertItem) && e.Item.IsInEditMode)
       //item is about to be edit  
       {
           long tipoParametro = long.Parse(((HiddenField)e.Item.FindControl("HiddenFieldTipoControllo")).Value);
           if (tipoParametro == (int)CommonParameters.TipoParamDatiAziendali.CheckBox_ComboBox || tipoParametro == (int)CommonParameters.TipoParamDatiAziendali.ComboBox)
               //RadComboBoxValore load values and selectedvalue
           ((RadComboBox)e.Item.FindControl("RadComboBoxValore")).DataSource = Utility.ValoriComboBox(((HiddenField)e.Item.FindControl("HiddenFieldQueryRiga")).Value, long.Parse(hdfIdCultura.Value));
           ((RadComboBox)e.Item.FindControl("RadComboBoxValore")).DataValueField = "Valore";
           ((RadComboBox)e.Item.FindControl("RadComboBoxValore")).DataTextField = "Descrizione";
           ((RadComboBox)e.Item.FindControl("RadComboBoxValore")).SelectedValue = ((HiddenField)e.Item.FindControl("HiddenFieldSelectedValueRadComboBoxValore")).Value;
           try
           {
               ((RadComboBox)e.Item.FindControl("RadComboBoxValore")).DataBind();
           }
           catch (ArgumentOutOfRangeException exc)
           {
               ErrorMessage.generatePopUpError(RadWindowErrori, ((SessionInformation)Session["sessionData"]).IdCultura, exc, null);
           }
           try
           {
               switch (tipoParametro)
               {
                   case (int)CommonParameters.TipoParamDatiAziendali.CheckBox :
                       //CheckBox
                       ((RadComboBox)e.Item.FindControl("RadComboBoxValore")).Visible = false;
                       ((TextBox)e.Item.FindControl("TextBoxDescrizione")).Visible = false;
                       ((CheckBox)e.Item.FindControl("CheckBoxAbilitatoE")).Visible = true;
                       break;
                   case (int)CommonParameters.TipoParamDatiAziendali.CheckBox_ComboBox :
                       //CheckBox-ComboBox
                       ((RadComboBox)e.Item.FindControl("RadComboBoxValore")).Visible = true;
                       ((TextBox)e.Item.FindControl("TextBoxDescrizione")).Visible = false;
                       ((CheckBox)e.Item.FindControl("CheckBoxAbilitatoE")).Visible = true;
                       break;
                   case (int)CommonParameters.TipoParamDatiAziendali.TextBox :
                       //TextBox
                       ((RadComboBox)e.Item.FindControl("RadComboBoxValore")).Visible = false;
                       ((TextBox)e.Item.FindControl("TextBoxDescrizione")).Visible = true;
                       ((CheckBox)e.Item.FindControl("CheckBoxAbilitatoE")).Visible = false;
                       break;
                   case (int)CommonParameters.TipoParamDatiAziendali.ComboBox :
                       //ComboBox
                       ((RadComboBox)e.Item.FindControl("RadComboBoxValore")).Visible = true;
                       ((TextBox)e.Item.FindControl("TextBoxDescrizione")).Visible = false;
                       ((CheckBox)e.Item.FindControl("CheckBoxAbilitatoE")).Visible = false;
                       break;
                   case (int)CommonParameters.TipoParamDatiAziendali.CheckBox_TextBox :
                       //CheckBox-TextBox
                       ((RadComboBox)e.Item.FindControl("RadComboBoxValore")).Visible = false;
                       ((TextBox)e.Item.FindControl("TextBoxDescrizione")).Visible = true;
                       ((CheckBox)e.Item.FindControl("CheckBoxAbilitatoE")).Visible = true;
                       break;
               }
           }
           catch (NullReferenceException)
           {
           }
             
       }
       else if (e.Item is GridDataItem)
       {
           //RadComboBoxValore load values and selectedvalue
           if (!String.IsNullOrEmpty(((HiddenField)e.Item.FindControl("HiddenFieldQueryRiga")).Value) && (((HiddenField)e.Item.FindControl("HiddenFieldTipoControllo")).Value == "4"))
           {
               ((RadComboBox)e.Item.FindControl("RadComboBoxValore")).DataSource = Utility.ValoriComboBox(((HiddenField)e.Item.FindControl("HiddenFieldQueryRiga")).Value, 0);
               ((RadComboBox)e.Item.FindControl("RadComboBoxValore")).DataValueField = "Key";
               ((RadComboBox)e.Item.FindControl("RadComboBoxValore")).DataTextField = "Value";
               ((RadComboBox)e.Item.FindControl("RadComboBoxValore")).SelectedValue = ((HiddenField)e.Item.FindControl("HiddenFieldSelectedValueRadComboBoxValore")).Value;
               ((Label)e.Item.FindControl("LabelDescrizioneI")).Visible = false;
               ((RadComboBox)e.Item.FindControl("RadComboBoxValore")).DataBind();
           }
           else
           {
               ((RadComboBox)e.Item.FindControl("RadComboBoxValore")).Visible = false;
           }
       }
   }

I really don't understand why the radcombobox lost everithing when i click the Edit column. I used the same tecniche to fill the combo if " IsInEditMode" or  if (e.Item is GridDataItem).

Thanks everybody !!!!

 

archimede
Top achievements
Rank 1
 answered on 19 Sep 2011
2 answers
101 views
I have one GridBoundColumn in a RadGrid where I don't want this functionality.  Is there a way to disable it on one column?

Thanks,

Kent
Kent
Top achievements
Rank 1
 answered on 19 Sep 2011
0 answers
93 views
hi telerik team

How to post uploaded files to another ip using multiple file selecion,
Ferrdins
Top achievements
Rank 1
 asked on 19 Sep 2011
1 answer
65 views
Hi all,

I am using comma for the thousands separator (like 5,000) into the numeric columns.
When I filter this value by writing the value with comma (like 5,000) into the filter box, I got an error message. Filtering without a comma (like 5000) works.

The users will filter the values writing commas so I need to solve this issue.  Can you please help me?

Thanks,
Ervin
Mira
Telerik team
 answered on 19 Sep 2011
2 answers
232 views
Hi,

I'm new to developing world as well as telerik.I have a web app where I'm using telerik controls.
I wanting to be able to size a rad window on open to the parent's size from code behind as to accmodate different resolutions.
Im using vb.net.

Im currently using the below but thats at a fixed pixel which is not what I'm looking for.

          

Private

Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button1.Click

Dim rw As New RadWindow

rw.ShowContentDuringLoad =

True

rw.Width = Unit.Pixel(1200)

 

rw.Height = Unit.Pixel(600)

rw.KeepInScreenBounds =

True

rw.Modal =

 

True

rw.NavigateUrl =

 

"test.aspx"

rw.VisibleOnPageLoad =

 

True

RadWindowManager1.Windows.Add(rw)
End Sub

 



Any help would be appreciated. Thanks
Derek
Top achievements
Rank 1
 answered on 19 Sep 2011
1 answer
89 views
I have a radgrid, bind to a collection list ( a list of data entitis).

One the grid_update command, GridTextBoxColumnEditor editor = (GridTextBoxColumnEditor)editMan.GetColumnEditor("Notes") returns "specificied argument was out of the range of valid value" error. But Notes is one of the item in my Collection class. Why?

radgrid update won't work for collection?


protected void rgDesigLevel_UpdateCommand(object sender, GridCommandEventArgs e)
       {
           
             
           switch (e.Item.OwnerTableView.Name)
           {
               case "Master":
                 
                   string Level1Notes="";
                   CustomerFileHistoryManager cfhm = new CustomerFileHistoryManager();
                   foreach (GridDataItem item in rgDesigLevel.EditItems)
                   {
                       Int32 AuditCustomerId = Convert.ToInt32(item.GetDataKeyValue("ID"));
                       GridEditManager editMan = item.EditManager;
                       GridTextBoxColumnEditor editor = (GridTextBoxColumnEditor)editMan.GetColumnEditor("Notes");
                       Level1Notes = editor.TextBoxControl.Text;
                       cfhm.UpdatePreProcNotes(AuditCustomerId, Level1Notes);
                   }
                   break;                       
           }
       }
   }
Thanks
Mira
Telerik team
 answered on 19 Sep 2011
1 answer
112 views
Hi, I want to get values from grid from two columns.
I have a function for getting values from one column:

string tmp = String.Empty;
            if (rg.SelectedItems.Count > 0)
            {
                int i = 0;
                foreach (GridDataItem DataItem in RadGrid.SelectedItems)
                {
                    TableCell cell = DataItem[columnName];
                    if (cell.Text.Length > 0 && cell.Text != " ")
                    {
                        tmp = String.Format("{0}{1}{2}", tmp, i > 0 ? ";" : "", cell.Text);
                    }
                    i++;
                }
            }
            return tmp;
For example my grid contains data:
Column1  Column2 Column3
1    2 3
4    5 6
7    8 9
If I execute code 2 times (for Column1 and Column3, could I be sure thay values will be:
"1;7" and "3;9" (right order, from top to bottom in those 2 cases)?
 Or the order could be random for example: "1;7" and "9, 3"?
Andrey
Telerik team
 answered on 19 Sep 2011
Narrow your results
Selected tags
Tags
+? more
Top users last month
Boardy
Top achievements
Rank 2
Veteran
Iron
Benjamin
Top achievements
Rank 3
Bronze
Iron
Veteran
ivory
Top achievements
Rank 1
Iron
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
ClausDC
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Boardy
Top achievements
Rank 2
Veteran
Iron
Benjamin
Top achievements
Rank 3
Bronze
Iron
Veteran
ivory
Top achievements
Rank 1
Iron
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
ClausDC
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?