问题描述
您好b $ b
要求--->我有Girdview,其中行是动态创建的,它有5列我需要第5列,即UserParameters,这是文本字段,用户将键入我想限制为15个字符的详细信息。
我已经尝试了这个<%#Eval(UserParameters)。ToString()。长度> 25? (Eval(UserParameters)as string).Substring(0,25):Eval(UserParameters)%>但是没有去..请帮我解决这个问题谢谢
下面是代码
Hi
Requirement---> I have Girdview where rows are dynamically created and it has 5 Columns I need the 5th column i.e UserParameters, which is text field where user will key in the details i want to restrict to 15 Characters.
I have already tried this <%# Eval("UserParameters").ToString().Length>25 ? (Eval("UserParameters") as string).Substring(0,25) : Eval("UserParameters") %> but no go .. Please help me to fix this problem thank you
Below is the code
<asp:GridView ID="gvTestScript" runat="Server" CssClass="GridViewStyle" AutoGenerateColumns="False" CellPadding="4"
ForeColor="Black" DataKeyNames="TestScriptID" ShowFooter="false"
Height="110px" Style="margin-right: 0px" Width="990px" BackColor="White" OnRowDataBound="gvTestScript_RowDataBound"
AutoGenerateEditButton="True" OnRowEditing="gvTestScript_RowEditing" OnRowCancelingEdit="gvTestScript_RowCancelingEdit"
OnRowUpdating="gvTestScript_RowUpdating" OnRowDeleted="gvTestScript_RowDeleted"
BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
OnRowCommand="gvTestScript_RowCommand">
<Columns>
<asp:TemplateField HeaderText="TestScriptID" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="lblTestScriptID" runat="server" Height="20px" Text='<%#Eval("TestScriptID")%>'> </asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Options" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:ImageButton ID="btnDelete" runat="server" ImageUrl="images/delete.ico" CausesValidation="false"
CommandName="DeleteRow" OnClick="btnDelete_Click" OnClientClick='return confirm("Are you sure you want to delete?");' />
</ItemTemplate>
<FooterTemplate>
<asp:ImageButton ID="btnSave" runat="server" ImageUrl="images/save.ico" CausesValidation="false"
CommandName="SaveRow" OnClick="btnSave_Click" />
</FooterTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="StepTableName" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="lblStepTableName" runat="server" Height="20px" Text='<%#Eval("StepName")%>'> </asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left"></ItemStyle>
<EditItemTemplate>
<asp:DropDownList ID="ddlStepTableName" runat="server" Visible="true" AutoPostBack="True"
OnSelectedIndexChanged="ddlStepTableName_SelectedIndexChanged">
</asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlFooterStepTableName" runat="server" Visible="true" AutoPostBack="True"
OnSelectedIndexChanged="ddlFooterStepTableName_SelectedIndexChanged">
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Test Data" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="lblTestData" runat="server" Height="20px" Text='<%#Eval("Aruguments")%>'> </asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left"></ItemStyle>
<EditItemTemplate>
<asp:DropDownList ID="ddlTestData" runat="server" Visible="true" AutoPostBack="True"
OnSelectedIndexChanged="ddlTestData_SelectedIndexChanged">
</asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlFooterTestData" runat="server" Visible="true" AutoPostBack="True"
OnSelectedIndexChanged="ddlFooterTestData_SelectedIndexChanged">
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="lblDescription" runat="server" Height="20px" Text='<%#Eval("Descritpion")%>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left"></ItemStyle>
<EditItemTemplate>
<asp:TextBox ID="txtDescription" runat="server" Text='<%# Bind("Descritpion")%>'
Visible="true">
</asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtFooterDescription" runat="server" Visible="true"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="UserParameters" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<%--<asp:Label ID="lblUserParameters" runat="server" Height="20px" Text='<%#Eval("UserParameters")%>'></asp:Label>--%>
<asp:Label ID="lblUserParameters" runat="server" Height="20px" Text='<%# Eval("UserParameters").ToString().Length>25 ? (Eval("UserParameters") as string).Substring(0,25) : Eval("UserParameters") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left"></ItemStyle>
<EditItemTemplate>
<asp:TextBox ID="txtUserParameters" runat="server" Text='<%# Bind("UserParameters") %>'
Visible="true">
</asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtFooterUserParameters" runat="server" Visible="true"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" HorizontalAlign="Justify"
VerticalAlign="Middle" />
<SortedAscendingCellStyle BackColor="#F7F7F7" />
<SortedAscendingHeaderStyle BackColor="#4B4B4B" />
<SortedDescendingCellStyle BackColor="#E5E5E5" />
<SortedDescendingHeaderStyle BackColor="#242121" />
<EmptyDataTemplate>
<table>
<tr style="background-color: #999999;">
<th>
Option
</th>
<th>
StepTableName
</th>
<th>
Test Data
</th>
<th>
Description
</th>
<th>
UserParameters
</th>
</tr>
<tr>
<td headers="Option">
<asp:ImageButton ID="btnSave" runat="server" ImageUrl="images/save.ico" CausesValidation="false"
CommandName="FirstSaveRow" OnClick="btnSave_Click" />
</td>
<td headers="StepTableName">
<asp:DropDownList ID="ddlFooterStepTableName" runat="server" Visible="true" >
</asp:DropDownList>
</td>
<td headers="Test Data">
<asp:DropDownList ID="ddlFooterTestData" runat="server" Visible="true" >
</asp:DropDownList>
</td>
<td headers="Description">
<asp:TextBox ID="txtFooterDescription" runat="server" Visible="true"></asp:TextBox>
</td>
<td headers="UserParameters">
<asp:TextBox ID="txtFooterUserParameters" runat="server" Visible="true"></asp:TextBox>
</td>
</tr>
</table>
</EmptyDataTemplate>
</asp:GridView>
推荐答案
<asp:TextBox ID="txtUserParameters" MaxLength="25" runat="server" Text='<%# Bind("UserParameters") %>'
Visible="true">
</asp:TextBox>
这篇关于如何限制特定列中GridView内的文本长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!