I have created Telerik Grid like this and item Bound Function also shown like as follows:
Please tell me if I resized the columns then how will I get the width of column present in RadGrid.Please find that telerik Auto Generated Column is set to true.
"
Namespace="Microsoft.SharePoint.WebControls" %>
<%@ Register Assembly="Telerik.Web.UI, Version=2010.2.826.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Table runat="server">
<asp:TableRow>
<asp:TableCell>
<telerik:RadGrid ID="gridForPreNewEdit2" AllowPaging="true" ShowFooter="false" runat="server" AutoGenerateColumns="true" GridLines="Both">
</telerik:RadGrid>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
void grdViewForPreview_ItemDataBound(object sender, GridItemEventArgs e)
{
try
{
if (e.Item is GridDataItem)
{
GridDataItem item = e.Item as GridDataItem;
SPWeb web = SPContext.Current.Web;
SPList list = web.Lists[new Guid(ddlSrcList.SelectedValue)];
SPListItem itemCol = list.Items.Add();
var contex = SPContext.GetContext(this.Context, 0, list.ID, list.ParentWeb);
foreach (GridColumn column in item.OwnerTableView.RenderColumns)
{
if (column.HeaderText == "Delete")
{
ImageButton btnDeleteFor = new ImageButton();
btnDeleteFor.ID = column.UniqueName;
btnDeleteFor.Enabled = false;
item[column.HeaderText].Controls.Clear();
item[column.HeaderText].Controls.Add(btnDeleteFor);
}
else
{
foreach (ListItem lstItem in lbDisplayedCols.Items)
{
if (lstItem.Text.ToLower().Trim() == column.HeaderText.ToLower().Trim())
{
SPField listField = list.Fields[column.HeaderText];
if (listField.Type != SPFieldType.DateTime && listField.Type != SPFieldType.User)
{
Panel pnlForBFC = new Panel();
pnlForBFC.ID = "Field2_" + listField.InternalName;
BaseFieldControl bfc = listField.FieldRenderingControl;
bfc.ID = "Field_" + listField.InternalName;
bfc.ControlMode = SPControlMode.New;
bfc.EnableViewState = true;
bfc.RenderContext = contex;
bfc.ItemContext = contex;
bfc.IsValid = true;
bfc.Visible = true;
pnlForBFC.Controls.Add(bfc);
pnlForBFC.Enabled = false;
item[column.HeaderText].Controls.Clear();
item[column.HeaderText].Controls.Add(pnlForBFC);
}
else if (listField.Type == SPFieldType.User)
{
PeopleEditor peopleEditor = new PeopleEditor();
item[column.HeaderText].Controls.Clear();
item[column.HeaderText].Controls.Add(peopleEditor);
}
else if (listField.Type == SPFieldType.DateTime)
{
DateTimeControl dtControl = new DateTimeControl();
dtControl.ID = "Field_" + listField.InternalName;
dtControl.Enabled = false;
item[column.HeaderText].Controls.Clear();
item[column.HeaderText].Controls.Add(dtControl);
}
}
}
}
}
}
else if (e.Item is GridFooterItem)
{
GridFooterItem itemForFooter = e.Item as GridFooterItem;
foreach (ListItem chosenListCol in lbDisplayedCols.Items)
{
if (ViewState[chosenListCol.Text] != null)
{
Label lblForFooter = new Label();
lblForFooter.ID = "Field_" + chosenListCol.Text;
lblForFooter.Text = "0";
lblForFooter.Width = Unit.Percentage(100);
lblForFooter.BorderColor = Color.Black;
lblForFooter.BorderStyle = BorderStyle.Solid;
lblForFooter.BorderWidth = 1;
itemForFooter[chosenListCol.Text].Controls.Clear();
itemForFooter[chosenListCol.Text].Controls.Add(lblForFooter);
}
}
}