I want to display the TextBox inside a details view in a new line as i am fetching the data from database and trying to make a Form
How do i do this
code
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="520px"
AutoGenerateRows="False" GridLines="None">
<Fields>
<asp:TemplateField >
<ItemTemplate>
<asp:TextBox ID="txtDtaLineDtchecked" runat="server" Text='<%# Bind("DtaLineDtChecked") %>' ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblDtaLineUsermatch" runat="server" Text='<%# Bind("DtaLineUserMatch") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
Please someone help?
try this
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="520px"
AutoGenerateRows="False" GridLines="None">
<Fields>
<asp:TemplateField >
<ItemTemplate>
<table>
<tr>
<td><asp:TextBox ID="txtDtaLineDtchecked" runat="server" Text='<%# Bind("DtaLineDtChecked") %>' ></asp:TextBox></td>
<td><asp:Label ID="lblDtaLineUsermatch" runat="server" Text='<%# Bind("DtaLineUserMatch") %>' ></asp:Label></td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
** i have put both data inside single templatefield
You can't
The DetailsView control is based on table-views
If you want to implement your custom design you would have to use the FormView control and use the correct templates. Example:
<asp:FormView runat="server" AllowPaging="true" ID="formView">
<ItemTemplate>
<%--customize the html--%>
</ItemTemplate>
However consider that the DetailsView control automatically creates the design for you, including controls in different modes like Edit, Insert and ReadOnly. When using the FormView control, you will have to provide templates for each mode
Try putting ItemFields in Table Row as follow...
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="520px" AutoGenerateRows="False" GridLines="None">
<Fields>
<table>
<tr>
<td>
<asp:TemplateField >
<ItemTemplate> <asp:TextBox ID="txtDtaLineDtchecked" runat="server" Text='<%# Bind("DtaLineDtChecked") %>' ></asp:TextBox> </ItemTemplate>
</asp:TemplateField>
</td>
<td>
<asp:TemplateField >
<ItemTemplate> <asp:Label ID="lblDtaLineUsermatch" runat="server" Text='<%# Bind("DtaLineUserMatch") %>' ></asp:Label> </ItemTemplate>
</asp:TemplateField>
</td>
</tr>
</table>
</Fields>
</asp:DetailsView>
Related
I have one Gridview with 5 columns including the edit column. When I click Edit I would like the last column EditItemTemplate Textbox 'The_Title' to take up the maximum width of the cell. It never does! (I can shrink the tbTitle with the Width attribute but not increase) I have tried many things including 'GridView1_RowDataBound'. What am I missing.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
for (int i = 0; i < e.Row.Cells.Count - 1; i++)
{
if (i == 4)
{
e.Row.Cells[i].Attributes.Add("style", "white-space:nowrap;padding:0px;margin:0px;width:500px");
}
}
}
GridView .aspx - only thing on the page no update panel (1 GV and 1 SqlDataSouce).
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" Width="1000px" OnRowEditing="GridView1_RowEditing" OnPreRender="GridView1_PreRender" OnRowDataBound="GridView1_RowDataBound" OnRowUpdated="GridView1_RowUpdated" OnRowUpdating="GridView1_RowUpdating">
<EditRowStyle BackColor="Red" Width="100%" />
<Columns>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="id" InsertVisible="False" SortExpression="id">
<EditItemTemplate>
<asp:Label ID="lblID1" runat="server" Text='<%# Eval("id") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblID2" runat="server" Text='<%# Bind("id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="The_Source" SortExpression="The_Source">
<EditItemTemplate>
<asp:TextBox ID="tbSrc" runat="server" Text='<%# Bind("The_Source") %>' Width="50px" ></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblSrc" runat="server" Text='<%# Bind("The_Source") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Section" SortExpression="Section">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Section") %>' Width="50px"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("Section") %>' Width="50px"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="The_Title" SortExpression="The_Title" HeaderStyle-Width="500px" HeaderStyle-BackColor="Red">
<EditItemTemplate>
<div style="white-space:nowrap;background-color:blue;text-align:center;padding:0px;margin:0px;">
<asp:TextBox ID="tbTitle" runat="server" Text='<%# Bind("The_Title") %>' Width="500px" style="white-space:nowrap;"></asp:TextBox>
</div>
</EditItemTemplate>
<ItemTemplate >
<asp:Label ID="lblTitle" runat="server" Text='<%# Bind("The_Title") %>' Width="500px"></asp:Label>
</ItemTemplate>
<ControlStyle BackColor="#3399FF" />
</asp:TemplateField>
</Columns>
</asp:GridView>
// Result image
Any clues would be appreciated. Thank You.
Using Browser developer tools, you should be able to inspect the resulting mark-up (HTML) for your text box and tinker with it to see what is causing the size restriction.
IE developer tools (F12) will show you the hierarchical (cascading) order where the width setting is being defined.
Tested your GridView. The TextBox tbTitle is 500 px wide, just as expected. There is probably some bootstrap or other css overwriting the width.
What happens if you add a class for it?
<EditItemTemplate>
<asp:TextBox ID="tbTitle" runat="server" CssClass="fullWidth" Text='<%# Bind("The_Title") %>'></asp:TextBox>
</EditItemTemplate>
.fullWidth {
width: 100% !important;
}
Or set it inline as !important. If that does not work then there is probably something else going on.
<asp:TextBox ID="tbTitle" runat="server" style="width: 100% !important" Text='<%# Bind("The_Title") %>'></asp:TextBox>
Is it possible to access the Text of ProductName inside this Hyperlink (DATALIST) ?
Thank you!!
<asp:DataList ID="DataList1" runat="server" CellPadding="0" RepeatColumns="4" RepeatDirection="Horizontal" ShowFooter="False" ShowHeader="False" OnSelectedIndexChanged="DataList1_SelectedIndexChanged">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" Text='<%# Eval("productName") %>' runat="server" Font-Size="Large"></asp:HyperLink>
</ItemTemplate>
</asp:DataList>
I have a nested grid. I would like to validate a dropdown control within the child grid when the user adds a record. But in a nested grid, the control IDs are not unique. If you have 2 parent rows and a nested grid under each parent the child grid controls will have the same ID. When I validate, the validation is checking all of the nested grids and not just the one that I am trying to add to.
This is the markup:
<asp:GridView ID="GroupGridView" runat="server" AutoGenerateColumns="False"
Caption="Group Information" CaptionAlign="Top" CssClass="grid"
ShowFooter="true" DataKeyNames="GroupID">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<a href="javascript:DivExpandCollapse('div<%# Eval("GroupID")%>');">
<img id="imgdiv<%# Eval("GroupID")%>" width="25px" border="0" src="Images/plus.png" /> </a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="GroupID">
<ItemTemplate>
<asp:Label ID="uggvLblGroupID" runat="server" Text='<%# Bind("GroupID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Group Name">
<ItemTemplate>
<asp:Label ID="uggvLblGroupName" runat="server" Text='<%# Bind("GroupName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Action" ItemStyle-Wrap="false" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Button ID="uggvDeleteButton" runat="server" CausesValidation="False" CommandName="Delete"
Text="Delete" CssClass="gridActionbutton" OnClientClick="return confirm('Are you sure you want to delete this Group Information?')" >
</asp:Button>
<tr><td colspan="100%">
<div id="div<%# Eval("GroupID") %>" style="display:none">
<asp:GridView ID="GroupMemberGridView" runat="server" AutoGenerateColumns="false"
CssClass="grid" ShowFooter="true">
<Columns>
<asp:TemplateField HeaderText="MemberID">
<ItemTemplate>
<asp:Label ID="mggvLblMemberID" runat="server" Text='<%# Bind("MemberID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Member Name" ItemStyle-Wrap="false">
<ItemTemplate>
<asp:Label ID="mggvLblMemberName" runat="server" Text='<%# Bind("MemberName") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="mggvDDLMemberName" runat="server" ClientIDMode="Static"
class="chosen-single" data-placeholder="Choose member…">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="ReqValueDDLMemberInsert" runat="server" InitialValue="0"
ControlToValidate="mggvDDLMemberName" ValidationGroup="'<%# "InsertGroupMemberValidation_" + Eval("GroupID") %>'
ErrorMessage="Selection required." CssClass="message-error-dropdown">
</asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Action" ItemStyle-Wrap="false" ItemStyle-HorizontalAlign="Center">
<FooterTemplate>
<asp:Button ID="mggvAddButton" runat="server" CommandName="Add" Text="Add Member" Width="90%"
CssClass="gridActionbutton" ValidationGroup='<%# "InsertGroupMemberValidation_" + Eval("GroupID") %>'> CausesValidation="true">
</asp:Button>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="uggvAddButton" runat="server" CommandName="Add" Text="Add Group" Width="90%" CausesValidation="true"
CssClass="gridActionbutton" ValidationGroup="InsertGroupNameValidation"
</asp:Button>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Regardless of which 'Add Member' button I click, the validation is triggered for all of the nested grids because the Validation Groups are not unique.
How can I uniquely identify the ValidationGroup for each nested grid?
Thanks.
UPDATE
The ValidationGroup identifier works when adding a member to the first nested group but not to subsequent nested grids. It seems it is still going thru all of the nested grids and not just the one from the 'Add' button you clicked.
//Access Validators and Buttons
RequiredFieldValidator RequiredFieldValidator1 = (RequiredFieldValidator)e.Row.FindControl("RequiredFieldValidator1");
RequiredFieldValidator RequiredFieldValidator2 = (RequiredFieldValidator)e.Row.FindControl("RequiredFieldValidator2");
RequiredFieldValidator RequiredFieldValidator3 = (RequiredFieldValidator)e.Row.FindControl("RequiredFieldValidator3");
Button Button = (Button)e.Row.FindControl("Button1");
//Assign validation group to controls.
RequiredFieldValidator1.ValidationGroup = "Gridview1" + e.Row.RowIndex.ToString();
RequiredFieldValidator2.ValidationGroup = "Gridview1" + e.Row.RowIndex.ToString();
RequiredFieldValidator3.ValidationGroup = "Gridview1" + e.Row.RowIndex.ToString();
Button.ValidationGroup = "Gridview1" + e.Row.RowIndex.ToString();
In the below code i have a grid view in which i have a textbox i am passing 0 and 1 to check box if it is 1 the checkbox to be checked.I tried but it is not working.Pls help me to solve the issue.
<asp:TemplateColumn HeaderText="Sales Price Ref" ItemStyle-Width="200px" HeaderStyle-VerticalAlign="Top">
<HeaderTemplate>
<asp:Label ID="lblSalesPriceRef" runat="server" Text="Sales Price"></asp:Label>
<br /><br />
<asp:TextBox runat="server" ID="txtSalesPriceRef" AutoPostBack="true" BorderStyle="Solid" BorderColor="#6495ED" BackColor="#B0C4DE" Height="20px" Width="90px" OnTextChanged="txtItem_TextChanged"></asp:TextBox>
</HeaderTemplate>
<EditItemTemplate>
<asp:CheckBox ID="ChSalesPriceRef" runat="server" Checked='<%#Eval("SalesPriceRef")=="1" ? true:false %>' />
<%-- <asp:TextBox ID="txtSalesPriceRef" Width="90px" runat="server" Text='<%#Eval("SalesPriceRef") %>'></asp:TextBox>--%>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblSalesPriceRef" runat="server" Text='<%# Convert.ToString(Eval("SalesPriceRef"))== "1" ? "True" :"False" %>' > </asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
YES you can achieve it by binding it to the checkbox
as
<asp:CheckBox ID="ChSalesPriceRef" runat="server" Checked='<%# Bind("SalesPriceRef")%>' Enabled="false" />
if you allow to change checkbox value then make enable=true
me problem is next:
I have a DetailsView control with many editItemTemplates some work fine but i have one dont work's.
code here:
<asp:TemplateField HeaderText="Date" SortExpression="date">
<ItemTemplate>
<%#this.putDate(Eval("fecha")) %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="date" runat="server" ></asp:TextBox>
<asp:CalendarExtender id="CE" runat="server" Format="dd/MM/yyyy"
PopupButtonID="calImg" TargetControlID="date">
</asp:CalendarExtender>
<asp:ImageButton id="calImg" runat="server" CommandName=""
ImageUrl="img/imgCal.gif" />
</EditItemTemplate>
</asp:TemplateField>
In view mode the information appear right but in edit mode after select new date with calendar and pres accept to update information, the data dont update. Any idea?
Thz!
Replace:
<asp:TextBox ID="date" runat="server" ></asp:TextBox>
With:
<asp:TextBox ID="date" runat="server" Text='<%# Bind("SelectedDate") %>'></asp:TextBox>