Im trying to create a Gridpanel from codebehind with varying Columns.
No clue why it doesn't work, I'm not getting an error just the Columns won't appear.
Ive got a Store and a Gridpanel in Markup Code:
<ext:Store ID="Store_X" runat="server" AutoLoad="false" OnReadData="Store_X_refresh">
<Proxy>
<ext:PageProxy />
</Proxy>
</ext:Store>
[...]
<ext:GridPanel runat="server" ID="gp_center" Region="Center" StoreID="Store_X" Title="X Tracking" >
<ColumnModel >
<Columns>
<ext:RowNumbererColumn ID="RowNumbererColumn2" runat="server" />
</Columns>
</ColumnModel>
</ext:GridPanel>
In my Store_X_refresh i have a List<KeyValuePair<string, int>> fieldStringList = new List<KeyValuePair<string, int>>(); into wich i load what Columns I want (depending on options selected). Before I access Database im doing this:
Ext.Net.Model newModel = new Ext.Net.Model();
foreach (var item in fieldStringList)
{
newModel.Fields.Add(new Ext.Net.ModelField() { Name = item.Key });
gp_center.ColumnModel.Columns.Add(new Ext.Net.Column() { DataIndex = item.Key, ID = "col_" + item.Key, Text = item.Key, Width = item.Value });
}
Store_X.Model.Add(newModel);
when I debug it, the Models get the right Data but the Gridpanel on UI doesn't have the Columns...
When I put Columns in store/columnmodel manually in markupcode the Gridgets correct Data so its not about some .DataBind() nor my DB-functionality
If you are changing ColumnModel of a Grid during a DirectEvent you should Reconfigure it. Please, look at this example: http://examples.ext.net/#/GridPanel/Data_Presentation/Grid_and_Store_Reconfigure/
Related
I have a simple RadMultiColumnComboBox in my aspx page with tag
<telerik:RadMultiColumnComboBox ID="RadMultiColumnComboBox1" RenderMode="Lightweight" runat="server" Filter="StartsWith" OnItemDataBound="RadMultiColumnComboBox1_ItemDataBound">
</telerik:RadMultiColumnComboBox>
How can I add ColumnsCollection-->MultiColumnComboBoxColumn fields from code behind.
What I am trying to achieve is creating a user control for MultiColumnComboBox so that it can be reused in various screens as per my need. Thus each page has different data and I need to bind the data from code behind instead of doing it from the design page like:
<telerik:RadMultiColumnComboBox runat="server" ID="RadMultiColumnComboBox1"
Width="220px" Height="400"
DataTextField="text" DataValueField="value">
<ColumnsCollection>
<telerik:MultiColumnComboBoxColumn Field="text" Title="Text">
</telerik:MultiColumnComboBoxColumn>
<telerik:MultiColumnComboBoxColumn Field="value" Title="Value">
</telerik:MultiColumnComboBoxColumn>
</ColumnsCollection>
</telerik:RadMultiColumnComboBox>
Please help.
Got the solution.
RadMultiColumnComboBox1.DataValueField = "ID";
RadMultiColumnComboBox1.DataTextField = "Name";
foreach (DataColumn item in dt.Columns)
{
RadMultiColumnComboBox1.ColumnsCollection.Add(new MultiColumnComboBoxColumn()
{
Field = item.ColumnName,
Title = item.ColumnName
});
}
RadMultiColumnComboBox1.DataSource = dt;
RadMultiColumnComboBox1.DataBind();
You have to fetch the data from DB into the data table
I am using batch editing in a radgrid with save button outside the grid. In side grid there are template columns and their edit templates have multiple values. I am able to assign values to them. But when I click on save in side bath edit command method the corresponding key of newvalues gives value of [object object]
<telerik:GridTemplateColumn HeaderText="Dwg Sch" ColumnGroupName="WACompOrderEntry" UniqueName="DwgSchedule" HeaderTooltip="This is the date the factory has promised to provide approval drawings to the field (loaded automatically from Vista when available)">
<ItemTemplate>
<asp:Label runat="server" ID="lblRdDwgSch" Text='<%# Eval("Vista_Sub", "{0:M/d/yy}") %>' ToolTip="This is the date the factory has promised to provide approval drawings to the field (loaded automatically from Vista when available)"></asp:Label>
<br />
<asp:Label ID="lblDwgSch" runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadDatePicker ID="rdDwgSch" runat="server" Width="80px" DbSelectedDate='<%# Eval("Vista_Sub", "{0:M/d/yy}") %>' ToolTip="This is the date the factory has promised to provide approval drawings to the field (loaded automatically from Vista when available)"></telerik:RadDatePicker>
<asp:TextBox ID="txtDwgSch" runat="server" Width="80px" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
Above is the template column definition
protected void gridMilestoneMatrixEntry_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
{
if (e.Commands == null)
{
return;
}
Cache.Remove("MileStoneData");
var updatedCommands = e.Commands.Where(x => x.Type == GridBatchEditingCommandType.Update);
var deletedCommands = e.Commands.Where(x => x.Type == GridBatchEditingCommandType.Delete);
List<int> updatedRecords = new List<int>();
List<long> deletedRecords = new List<long>();
if (updatedCommands != null && updatedCommands.Count() > 0)
{
updatedRecords = UpdateMilestoneMatrix(updatedCommands.ToList());
}
Now inside the hashtable key values do not give values for object
updatedValues["DwgSchedule"] it gives value as [object object]
if (updatedValues["DwgSchedule"] != null)
{
tempStr = updatedValues["DwgSchedule"].ToString();
if (!string.IsNullOrEmpty(tempStr))
{
confDwgExp = DateTime.ParseExact(updatedValues["DwgSchedule"].ToString(), "M/d/yyyy", CultureInfo.InvariantCulture);
}
tempStr = string.Empty;
}
The way I decided to go about doing these things was to have the iterate through the rows of the grid by using the RadGrid.Items
This allows you to access each individual row, which in essence gives you access to the row's individual controls (i.e not just the cells, but everything on the row).
Private Sub RbtnSaveAll_Click(sender As Object, e As EventArgs) Handles RbtnSaveAll.Click
For Each item As GridDataItem In grdActivities.Items 'Iterates over the rows
'Get your controls by using item.findcontrol("controlname").
'Then send the data of the changed controls to the datasource
Next
bindGrid(True) 'Do your bind event if necessary
End Sub
If you want a c# version you can simply convert it using telerik's converter
EDIT:
<asp:Button ID="btnBulkBookOn" runat="server" Text="Book On" CommandName="Update"/>
VB-code:
Private Sub radgrdResources_UpdateCommand(sender As Object, e As GridCommandEventArgs) Handles radgrdResources.UpdateCommand
' This will be invoked when you clikc the button and fire off the Radgrid's native save.
End Sub
I have a SP List with columns URL and Link Name. And I am binding it to the GridView.
Below is my GridView
<asp:GridView ID="GridView1" runat="server" GridLines="None" ShowHeader="false" AutoGenerateColumns="false">
<Columns>
<asp:HyperLinkField DataTextField="LinkName" DataNavigateUrlFields="URL" Target="_blank"/>
</Columns>
</asp:GridView>
and on the code behind
private void BindGridView(SPList list, string section, GridView grdView1)
{
SPQuery query = new SPQuery();
query.Query = "<Where><Eq><FieldRef Name=" + section + "/><Value Type='Choice'>" + section + "</Value></Eq</Where>";
query.ViewFieldsOnly = true;
query.ViewFields = "<FieldRef Name='URL'/>" + "<FieldRef Name='LinkName'/>";
SPListItemCollection listCollection = list.GetItems(query);
if (listCollection != null && listCollection.Count > 0)
{
grdView1.DataSource = listCollection.GetDataTable();
grdView1.DataBind();
}
}
Suppose I have the Link Name as Google and URL as www.google.com.
When I click on the hyperlink field of the GridView, the URL in the brower is //goog.com,%20//goo.com, because of which it does not navigate to the URL.
Someone please help me and let me know what am I doing wrong.
the correct way to use the Url Value field is by using the SPFieldUrlValue object.
Ex:
List<string> urls = new List<string>();
foreach (SPListItem item in listCollection)
{
urls.Add(new SPFieldUrlValue(item["URL"]).Url);
}
grdView1.DataSource = urls;
I have a grid that I need to add columns to dynamically (programatically).
I have been browsing Telerik forums as well as Google and im not able to find anything. Decompiling GridTemplateColumn shows that there should be ItemTemplate property however my VS throws an error.
Dim col As GridColumn = New GridButtonColumn()
col.UniqueName = stockLocation("LocationID").ToString()
col.HeaderText = stockLocation("Name").ToString()
col.ItemTemplate = ERROR HERE
rgGridCombinations.Columns.Add(col)
I'm trying to create a column that will look like following ASPX code.
<radg:GridTemplateColumn HeaderText="Stock" UniqueName="Stock" Visible="true" HeaderStyle-Width="10%">
<ItemTemplate>
<asp:TextBox ID="tbStock" runat="server" Width="100%" />
</ItemTemplate>
</radg:GridTemplateColumn>
How would I create this?
1) GridColumn does not have ItemTemplate property
2) You were assigning GridButtonColumn. Use GridTemplateColumn instead
Try this
Dim col = As New GridTemplateColumn()
col.UniqueName = "Stock"
col.HeaderText = "Stock"
col.ItemTemplate = <something here> 'should be an ITemplate
rgGridCombinations.Columns.Add(col)
For more information on how to create template, check here
I am adding columns to RadGrid from code behind. In NeedDataSource event, I am binding a DataTable(with 10 columns) to the radgrid.
Everything's working well till here. But I would like to have text boxes in 2 columns(on load itself, not just in edit mode).
<telerik:RadGrid ID="RadGrid1" runat="server" ShowHeader="true"
OnNeedDataSource="RadGrid1_NeedDataSource" OnPreRender="RadGrid1_PreRender"
AutoGenerateColumns="true" >
<MasterTableView>
</MasterTableView>
</telerik:RadGrid>
If done declarative, the column definition shall be like this. But I want it accomplished from code behind.
<telerik:GridTemplateColumn HeaderText="Qty">
<ItemTemplate>
<input id="<%# this.GetUniqueId("Qty", Container.DataItem)%>" name="<%# this.GetUniqueId("Qty", Container.DataItem)%>" type="text" value="<%# Eval("Quantity")%>" size="2" maxlength="3" />
</ItemTemplate>
</telerik:GridTemplateColumn>
Create TemplateColumn like any other column type and set template object to ItemTemplate (and you can do same for HeaderTemplate and FooterTemplate). But you have to define custom template class witch will implement ITemplate.
You can find an example here :
http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html#Section4
Must you use a template column? If you can directly bind your columns to a datasource field, use the GridNumericColumn. This can be dynamically added from the code behind:
GridNumericColumn numColumn = new GridNumericColumn();
numColumn.UniqueName = "ColumnId";
numColumn.MaxLength = 20;
numColumn.HeaderText = "My Numeric Column";
numColumn.DataField = "Qty";
numColumn.DataFormatString =
myGrid.MasterTableView.Columns.Add(numColumn);
Use This.
GridTemplateColumn tempCol;
for (int i = 0; i < obj.Count; i++)
{
tempCol = new GridTemplateColumn();
this.gvwRejection.MasterTableView.Columns.Add(tempCol);
tempCol.ItemTemplate = new DynamicTemplateCoulmn"txtCategoryQty"+ , "numericTextBox");
tempCol.HeaderText = objRejectionCategoryMasterObject[i].CategoryName.Trim();
tempCol.UniqueName = "CategoryQty" + i;
tempCol.HeaderStyle.HorizontalAlign = HorizontalAlign.Right;
tempCol.ItemStyle.HorizontalAlign = HorizontalAlign.Right;
tempCol.FooterStyle.HorizontalAlign = HorizontalAlign.Right;
RejCategoryIDs[i] = objRejectionCategoryMasterObject[i].RejCategoryID;
}
tempCol = new GridTemplateColumn();
this.gvwRejection.MasterTableView.Columns.Add(tempCol);
tempCol.ItemTemplate = new DynamicTemplateCoulmn("txtTotal", "numericTextBoxReadOnly");
tempCol.HeaderText = "Total";
tempCol.UniqueName = "Total";
tempCol.HeaderStyle.HorizontalAlign = HorizontalAlign.Right;
tempCol.ItemStyle.HorizontalAlign = HorizontalAlign.Right;
tempCol.FooterStyle.HorizontalAlign = HorizontalAlign.Right;