Hi.
I have a grid and when the user have a row in editmode, the textbox get so small that is not possible to write something in it and in the textbox field a cross i sho
wing. I use a method(SetTextBoxWidth) to regular the width to the column when RadGrid1_ItemDataBound event is called.
The code i am using is as following:
I have a grid and when the user have a row in editmode, the textbox get so small that is not possible to write something in it and in the textbox field a cross i sho
(The grid is a hierarchy with one level. ) I hope somebody have a clue why this is happening.The code i am using is as following:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AllowFilteringByColumn
=
"False"
AllowPaging
=
"True"
AllowSorting
=
"True"
GridLines
=
"None"
ShowStatusBar
=
"True"
Culture
=
"Norwegian, Bokmål (Norway)"
AutoGenerateColumns
=
"False"
Width
=
"700px"
onitemcommand
=
"RadGrid1_ItemCommand"
onitemdatabound
=
"RadGrid1_ItemDataBound"
onneeddatasource
=
"RadGrid1_NeedDataSource"
onupdatecommand
=
"RadGrid1_UpdateCommand"
>
<
MasterTableView
AutoGenerateColumns
=
"False"
DataKeyNames
=
"TransId"
EditMode
=
"InPlace"
CommandItemDisplay
=
"Top"
>
<
CommandItemTemplate
>
<
div
style
=
"text-align:right;margin:4px;"
>
<
asp:LinkButton
ID
=
"LinkButtonClose"
runat
=
"server"
CommandName
=
"CloseAll"
ToolTip
=
"Lukk alle radene"
>Lukk alle</
asp:LinkButton
>
<
asp:LinkButton
ID
=
"LinkButtonOpen"
runat
=
"server"
CommandName
=
"OpenAll"
ToolTip
=
"Utvid alle radene"
>Utvid alle</
asp:LinkButton
>
</
div
>
</
CommandItemTemplate
>
<
RowIndicatorColumn
><
HeaderStyle
Width
=
"20px"
></
HeaderStyle
></
RowIndicatorColumn
>
<
DetailTables
>
<
telerik:GridTableView
runat
=
"server"
AllowPaging
=
"False"
DataKeyNames
=
"DetailId"
AllowFilteringByColumn
=
"false"
EditMode
=
"InPlace"
DataSourceID
=
"DetailDataSource"
>
<
ParentTableRelation
><
telerik:GridRelationFields
DetailKeyField
=
"TransId"
MasterKeyField
=
"TransId"
/></
ParentTableRelation
>
<
CommandItemSettings
ExportToPdfText
=
"Export to Pdf"
></
CommandItemSettings
>
<
Columns
>
<
telerik:GridBoundColumn
UniqueName
=
"JourneyTime"
HeaderText
=
"Tur"
DataField
=
"JourneyTime"
ReadOnly
=
"true"
SortExpression
=
"JourneyTime"
>
<
HeaderStyle
Width
=
"40px"
></
HeaderStyle
><
ItemStyle
HorizontalAlign
=
"Left"
/></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
UniqueName
=
"RouteName"
HeaderText
=
"Rute"
DataField
=
"RouteName"
ReadOnly
=
"true"
SortExpression
=
"RouteName"
>
<
HeaderStyle
Width
=
"100px"
></
HeaderStyle
></
telerik:GridBoundColumn
>
<
telerik:GridNumericColumn
UniqueName
=
"DetailCount"
DataType
=
"System.Int32"
HeaderText
=
"Antall"
DataField
=
"DetailCount"
SortExpression
=
"DetailCount"
>
<
HeaderStyle
Width
=
"70px"
></
HeaderStyle
><
ItemStyle
HorizontalAlign
=
"Left"
/></
telerik:GridNumericColumn
>
<
telerik:GridNumericColumn
UniqueName
=
"TariffNr"
DataType
=
"System.Int32"
HeaderText
=
"Billettkode"
DataField
=
"TariffNr"
SortExpression
=
"TariffNr"
>
<
HeaderStyle
Width
=
"73px"
></
HeaderStyle
><
ItemStyle
HorizontalAlign
=
"Left"
/></
telerik:GridNumericColumn
>
<
telerik:GridNumericColumn
UniqueName
=
"UnitPrice"
HeaderText
=
"Pris"
DataField
=
"UnitPrice"
DataType
=
"System.Double"
SortExpression
=
"UnitPrice"
DecimalDigits
=
"2"
>
<
HeaderStyle
Width
=
"70px"
></
HeaderStyle
><
ItemStyle
HorizontalAlign
=
"Left"
/></
telerik:GridNumericColumn
>
<
telerik:GridEditCommandColumn
CancelText
=
"Avbryt"
EditText
=
"Endre"
InsertText
=
"Sett inn"
UpdateText
=
"Oppdater"
UniqueName
=
"EditColumn"
>
<
ItemStyle
HorizontalAlign
=
"Right"
/></
telerik:GridEditCommandColumn
>
</
Columns
>
<
EditFormSettings
>
<
EditColumn
UniqueName
=
"EditCommandColumn1"
></
EditColumn
>
</
EditFormSettings
>
</
telerik:GridTableView
>
</
DetailTables
>
<
CommandItemSettings
ExportToPdfText
=
"Export to Pdf"
></
CommandItemSettings
>
<
ExpandCollapseColumn
Visible
=
"True"
></
ExpandCollapseColumn
>
<
Columns
>
<
telerik:GridBoundColumn
FilterControlWidth
=
"95%"
UniqueName
=
"CardNumber"
DataField
=
"CardNr"
HeaderText
=
"Serienr."
ReadOnly
=
"true"
DataType
=
"System.Int64"
SortExpression
=
"CardNr"
>
<
HeaderStyle
Width
=
"78px"
></
HeaderStyle
><
ItemStyle
HorizontalAlign
=
"Right"
/></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
UniqueName
=
"TransDate"
DataField
=
"TransDate"
HeaderText
=
"Dato"
HeaderStyle-Width
=
"150px"
ReadOnly
=
"true"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
FilterControlWidth
=
"95%"
DataField
=
"UserNr"
DataType
=
"System.Int32"
HeaderText
=
"Brukernr."
ReadOnly
=
"True"
SortExpression
=
"UserNr"
UniqueName
=
"UserNumberStr"
>
<
HeaderStyle
Width
=
"105px"
></
HeaderStyle
><
ItemStyle
HorizontalAlign
=
"Right"
/></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
FilterControlWidth
=
"95%"
DataField
=
"TicketNr"
DataType
=
"System.Int32"
HeaderText
=
"Billettnr."
ReadOnly
=
"True"
SortExpression
=
"TicketNr"
UniqueName
=
"TicketNumberStr"
>
<
HeaderStyle
Width
=
"100px"
></
HeaderStyle
><
ItemStyle
HorizontalAlign
=
"Right"
/></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
FilterControlWidth
=
"95%"
DataField
=
"AnnulComment"
HeaderText
=
"Annullerings kommentar"
SortExpression
=
"AnnulComment"
UniqueName
=
"AnnulComment"
>
<
HeaderStyle
Width
=
"200px"
></
HeaderStyle
></
telerik:GridBoundColumn
>
<
telerik:GridEditCommandColumn
CancelText
=
"Avbryt"
EditText
=
"Endre"
InsertText
=
"Sett inn"
UpdateText
=
"Oppdater"
UniqueName
=
"EditColumn"
>
<
HeaderStyle
Width
=
"105px"
></
HeaderStyle
><
ItemStyle
HorizontalAlign
=
"Right"
/></
telerik:GridEditCommandColumn
>
<
telerik:GridButtonColumn
CommandName
=
"Annul"
Text
=
"Annuller"
UniqueName
=
"AnnulColumn"
>
<
HeaderStyle
Width
=
"60px"
></
HeaderStyle
></
telerik:GridButtonColumn
>
</
Columns
>
<
NoRecordsTemplate
><
div
>Det er ingen elementer å vise</
div
></
NoRecordsTemplate
>
</
MasterTableView
>
<
ClientSettings
EnableRowHoverStyle
=
"true"
>
<
Resizing
AllowColumnResize
=
"true"
/>
<
ClientEvents
OnRowDblClick
=
"RowDblClick"
/>
<
Selecting
AllowRowSelect
=
"true"
/>
</
ClientSettings
>
<
SortingSettings
EnableSkinSortStyles
=
"False"
SortedAscToolTip
=
"Sortert stigende"
SortedDescToolTip
=
"Sortet synkende"
SortToolTip
=
"Klikk her for å sortere"
/>
</
telerik:RadGrid
>
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item.IsInEditMode)
{
SetColumnWidthInEditMode(e);
if (e.Item.OwnerTableView == RadGrid1.MasterTableView)
{
SetFocusOnField(e, "AnnulComment");
}
}
else if (e.Item is GridDataItem)
{
LoadTransAndDetailValues(e);
}
}
private void SetColumnWidthInEditMode(GridItemEventArgs e)
{
if (!(e.Item is GridDataItem))
return;
var gridItem = (GridDataItem)e.Item;
if (e.Item.OwnerTableView == RadGrid1.MasterTableView)
{
SetTextBoxWidth(gridItem, "AnnulComment");
}
}
private void SetTextBoxWidth(GridDataItem item, string name)
{
TableCell cell = item[name];
if (cell == null)
return;
if (cell.Controls.Count > 0 && cell.Controls[0] is TextBox)
{
var box = (TextBox)cell.Controls[0];
box.Width = Unit.Percentage(95);
}
}
private void LoadTransAndDetailValues(GridItemEventArgs e)
{
var item = e.Item as GridDataItem;
if (e.Item.DataItem is Detail)
{
var detail = e.Item.DataItem as Detail;
if (detail.Trans.AnnulCode > 0)
{
SetRowInAnnulMode(item, true);
}
item["JourneyTime"].Text = detail.JourneyTime;
item["RouteName"].Text = detail.RouteName;
double? unitPrice = detail.UnitPrice;
if (e.Item.IsInEditMode)
{
var ntb = item["UnitPrice"].Controls[0] as RadNumericTextBox;
if (ntb != null && unitPrice.HasValue && unitPrice.Value != 0)
{
ntb.Value = unitPrice.Value / 100.00;
}
else
ntb.Value = null;
}
else if (unitPrice.HasValue && unitPrice != 0)
{
item["UnitPrice"].Text = CurrencyFormatting.DoubleToPrice((unitPrice.Value / 100.00));
}
}
else if (e.Item.DataItem is Trans)
{
var trans = e.Item.DataItem as Trans;
if (trans.AnnulCode > 0)
{
SetRowInAnnulMode(item, false);
}
}
}