change Width Gridview While containing 100 words; - c#

HTML
<asp:GridView ID="GridView1" runat="server" GridLines="Vertical" Width="825px" AutoGenerateColumns="False"
DataSourceID="LinqDataSource1">
<Columns>
<asp:BoundField DataField="Title" HeaderText="Title" ReadOnly="True"
SortExpression="Title" />
<asp:BoundField DataField="Body" HeaderText="Body" ReadOnly="True" ItemStyleWidth="1"
SortExpression="Body"></asp:BoundField>
</Columns>
</asp:GridView>
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="DataClassesDataContext"
Select="new (Title, Body)" TableName="PrivateMessages">
</asp:LinqDataSource>
Code
GridView1.Columns[1].ItemStyle.Width = 1;
i would like Fixed Columns[1].width=1 ; While Body containing 100 words;
This Code Does Not Change Width Gridview?

It's not necessary to change the GridView with drag and drop. You have to just select its edges and you can change it.

Related

Missing ComboBox on Grid Item Edit

I new to telerik and fighting my way up the learning curve.
I have a RadGrid that I'm populating with a linq query. I'm using a
GridTemplateColumn with a ComboBox for new and edit of one of the fields. The problem is the ComboBox doesn't show on the insert or edit screen. The fields set as GridDropDownColumn do show on the insert or edit. I need GridTemplateColumn solution because I need to run some code once the dropdown list has been selected.
What am I missing here? I'm trying to work from a Telerik example. It's the Release field that is giving me the problem.
<telerik:RadGrid RenderMode="Lightweight" ID="grdData" runat="server"
AllowPaging="true"
AllowSorting="true"
AutoGenerateColumns="false"
AllowAutomaticInserts="true"
AllowAutomaticUpdates="true"
OnNeedDataSource="grdData_OnNeededDataSource"
OnItemDataBound="grdData_OnItemDataBound"
OnUpdateCommand="grdData_OnUpdateCommand" >
<ClientSettings>
<Selecting AllowRowSelect="True" />
<Scrolling AllowScroll="True" UseStaticHeaders="True" />
</ClientSettings>
<SelectedItemStyle BackColor="LightYellow" />
<MasterTableView Width="100%"
DataKeyNames="TID"
EditMode="EditForms"
AutoGenerateColumns="false"
InsertItemDisplay="Top"
CommandItemDisplay="Top"
InsertItemPageIndexAction="ShowItemOnFirstPage">
<Columns>
<telerik:GridEditCommandColumn></telerik:GridEditCommandColumn>
<telerik:GridBoundColumn DataField="TID" UniqueName="TID"
HeaderText="TID" ReadOnly="true"></telerik:GridBoundColumn>
<telerik:GridDropDownColumn UniqueName="Employee" ListDataMember="Employee"
SortExpression="Employee" ListTextField="Employee" ListValueField="Employee"
HeaderText="Employee" DataField="Employee"
DropDownControlType="RadComboBox"
EnableEmptyListItem="true" EmptyListItemText="Make a choice" EmptyListItemValue=""
/>
<telerik:GridDropDownColumn UniqueName="Job" ListDataMember="Job"
SortExpression="Job" ListTextField="Job" ListValueField="Job"
HeaderText="Job" DataField="Job"
DropDownControlType="RadComboBox"
EnableEmptyListItem="true" EmptyListItemText="Make a choice" EmptyListItemValue=""
/>
<telerik:GridTemplateColumn UniqueName="Release"
HeaderText="Release"
HeaderStyle-HorizontalAlign="Center"
SortExpression="Release"
ItemStyle-Width="170px" HeaderStyle-Width="80px"
DataField="Release" >
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem, "Release")%>
</ItemTemplate>
<telerik:EditItemTemplate>
<telerik:RadComboBox runat="server" ID="rcbRelease"
AutoPostBack="true"
EnableLoadOnDemand="true"
DataTextField="Release"
DataValueField="Release"
Text='<% #Bind("Release")%>'
EnableEmptyListItem="true"
EmptyListItemText="Make a choice"
EmptyListItemValue="NR"
OnDataBinding="rcbRelease_OnDataBinding"
></telerik:RadComboBox>
</telerik:EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="ComponentJob" UniqueName="ComponentJob" HeaderText="ComponentJob"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Operation" UniqueName="Operation" HeaderText="Operation"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Quantity" UniqueName="Quantity" HeaderText="Quantity"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Priority" UniqueName="Priority" HeaderText="Priority"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Status" UniqueName="Status" HeaderText="Status"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="LastEdit" UniqueName="LastEdit" HeaderText="LastEdit"></telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
I think your having trouble with the ComboBox because you have EnableLoadOnDemand=true but you have not subscribed to the ItemsRequested event. See Load On Demand Overview for details.
Since you mention your new to the controls, you might want to get the ComboBox LoadOnDemand working outside of the grid first.
Try removing the telerik namespace/prefix from the EditItemTemplate declaration:
Change this:
<telerik:EditItemTemplate>
<%-- RadComboBox --%>
</telerik:EditItemTemplate>
To this:
<EditItemTemplate>
<%-- RadComboBox --%>
</EditItemTemplate>
Also, please share with us which documentation were you following so that we can double check and report the documentation error.

asp.net paging changes height

title says it all, I have a gridview, and the second page does not fill the 10 places so it changes height, I need the gridview to stay the same no matter what. I will change to whatever I need to get this done, Ive tried everything I can find online like taking out the height attribute and moving it to css, nothing has worked. I also tried all of the answers here and they did not work either...GridView paging problem!
the CSS i tried is:
.RowStyle {
height: 50px;
}
.AlternateRowStyle {
height: 50px;
}
and the HTML I am using currently is:
<asp:Panel runat="Server" ID="AnonymousMessagePanel">
<br />
<asp:GridView ID="CompletedProjectsGrid" runat="server" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="ProjectsClosedList"
EnableViewState="False" DataKeyNames="ProjectID" CssClass="mGrid" PagerStyle-CssClass="pgr" RowStyle-CssClass="RowStyle"
AlternatingRowStyle-CssClass="alt" AllowPaging="true" PageSize="10">
<Columns>
<asp:BoundField DataField="ProjectID" HeaderText="ProjectID" HeaderStyle-ForeColor="White" SortExpression="ProjectID" ReadOnly="True" ItemStyle-Width="11%"/>
<asp:BoundField DataField="ProjectName" HeaderText="ProjectName" HeaderStyle-ForeColor="White" SortExpression="ProjectName" ItemStyle-Width="11%"/>
<asp:BoundField DataField="TesterName" HeaderText="TesterName" HeaderStyle-ForeColor="White" SortExpression="TesterName" ItemStyle-Width="11%"/>
<asp:BoundField DataField="ProjectDescription" HeaderText="ProjectDescription" HeaderStyle-ForeColor="White" SortExpression="ProjectDescription" ItemStyle-Width="11%"/>
<asp:BoundField DataField="Platform" HeaderText="Platform" HeaderStyle-ForeColor="White" SortExpression="Platform" ItemStyle-Width="11%"/>
<asp:BoundField DataField="DueDate" HeaderText="DueDate" HeaderStyle-ForeColor="White" SortExpression="DueDate" dataformatstring="{0:M/dd/yyyy}" ItemStyle-Width="11%"/>
<asp:BoundField DataField="DateAssigned" HeaderText="DateAssigned" HeaderStyle-ForeColor="White" SortExpression="DateAssigned" dataformatstring="{0:M/dd/yyyy}" ItemStyle-Width="11%"/>
<asp:BoundField DataField="DocumentName" HeaderText="DocumentName" HeaderStyle-ForeColor="White" SortExpression="DocumentName" ItemStyle-Width="11%"/>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="ProjectsClosedList" runat="server"
ConnectionString="<%$ ConnectionStrings:ProjectsAndTasksTestConnectionString %>"
SelectCommand="SELECT [ProjectID], [ProjectName], [TesterName], [ProjectDescription], [Platform], [DueDate], [DateAssigned], [DocumentName] FROM [Projects] WHERE ([DateCompleted] IS NULL)">
</asp:SqlDataSource>
</asp:Panel>
Note: all of these ways do actually run and work, they just all change height of the gridview when there is only 2/10 on the last page, and I need it the same height no matter what is in the page
If this is not the best way to achieve this, I am open to better options
use box-sizing
.RowStyle,.AlternateRowStyle{
box-sizing: border-box
}
or just
* { box-sizing: border-box }
you can have a look at max-height too
Try to remove your RowStyle-CssClass="RowStyle and do this and see if it works:
<asp:BoundField DataField="ProjectID" HeaderText="ProjectID" HeaderStyle-ForeColor="White" SortExpression="ProjectID" ReadOnly="True">
<ItemStyle CssClass="RowStyle"></ItemStyle>
</asp:BoundField>
Somehow I feel some of your other styles are influencing the height.
Or try following:
.RowStyle
{
height: 50px !important;
}
.AlternateRowStyle
{
height: 50px !important;
}

Pre Sort GridView Items

I have a aspGridView Control. I am only using it to display information and it does not allow the user to filter. I would like to preset the information where it displays it using a descending sort on the column read_date. Can I do this from the controllers settings?
<asp:GridView AllowPaging="true" runat="server" ID="gridRead" AutoGenerateColumns='false' BorderStyle="None" GridLines="None" HorizontalAlign="Center" Width="200px" PageSize="12" >
<PagerSettings Visible="false" />
<Columns>
<asp:BoundField
HeaderText="Date"
HeaderStyle-HorizontalAlign="Left"
DataField="read_date"
Visible="true"
DataFormatString="{0:d}"
ItemStyle-HorizontalAlign="Left"
HeaderStyle-ForeColor="#004C7E"
HeaderStyle-Font-Underline="true"
ItemStyle-ForeColor="#004C7E"
ItemStyle-Font-Size="Medium"
/>
<asp:BoundField
HeaderText="Reading"
HeaderStyle-HorizontalAlign="Left"
DataField="reading"
Visible="true"
DataFormatString="{0:C}"
ItemStyle-HorizontalAlign="Left"
HeaderStyle-ForeColor="#004C7E"
HeaderStyle-Font-Underline="true"
ItemStyle-ForeColor="#004C7E"
ItemStyle-Font-Size="Medium"
ItemStyle-CssClass="datagridStyle"
/>
So I just want to display the grid with read_date descending. I am binding a DataSet to this grid. Thanks
Set the "order by" command in your stored procedure.

Get selected Index in gridview by clicking on button

I have grid view and there is a template field in it and i want to get the selected row's index by clicking on button i cant change the field type cause i want to change the visibale attribute in my behind code manually.
Here is my code:
<asp:GridView ID="gvService" runat="server" BackColor="White" AutoGenerateColumns="False"
BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical" DataKeyNames="Service_Id, UserId">
<AlternatingRowStyle BackColor="#DCDCDC" />
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" HeaderStyle-BackColor="Gray">
<HeaderStyle BackColor="Gray"></HeaderStyle>
</asp:BoundField>
<asp:BoundField DataField="L_Name" HeaderText="LastName" SortExpression="L_Name"
HeaderStyle-BackColor="Gray">
<HeaderStyle BackColor="Gray"></HeaderStyle>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="bttCost" runat="server" Text="Cost" OnCommand="Cmd_Pay" Visible='<%# IsNotPaid((Decimal)Eval("Cost")) %>' />
</ItemTemplate>
</asp:TemplateField>
and my behind code:
int rowIndex = gvService.SelectedIndex;
HFServiceID.Value = (string)gvService.DataKeys[rowIndex]["Service_Id"];
HFUserID.Value = (string)gvService.DataKeys[rowIndex]["UserId"];
To get the row index the button that was clicked belongs to, add this in your onclick event.
var rowIndex = ((GridViewRow)((Control)sender).NamingContainer).RowIndex;

ASP.NET/GridView: Using only a subset of the data fields in the table

I have a list of objects called Activity and I want to display the date, type and notes for each and every one of these activities. This is the code I'm using.
<asp:GridView ID="gvTable" runat="server" AllowSorting="true" ShowHeader="true">
<Columns>
<asp:BoundField DataField="ActivityDate" HeaderText="Date"
HeaderStyle-CssClass="date" />
<asp:BoundField DataField="ActivityType" HeaderText="Type" />
<asp:BoundField DataField="ActivityNotes" HeaderText="Notes" />
</Columns>
<PagerSettings Position="Bottom" Mode="NextPrevious" PageButtonCount="5"
PreviousPageText="Older activities" NextPageText="Newer activities" />
</asp:GridView>
However, all of the attributes of each object is displayed in the header. How can I force it to display only the columns that I want to use?
gvTable.AutoGenerateColumns = false
or
<asp:GridView ID="gvTable" runat="server" AutoGenerateColumns="False" AllowSorting="true" ShowHeader="true">
should do the trick.
Set the attribute on your gridview:
AutoGenerateColumns="false"
You need to set the AutoGenerateColumns property on the grid to false.
Have you tried AutoGenerateColumns="false" in the gridview?

Categories