Is it possible to edit a GridView cell without an edititemtemplate? - c#

<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="lclick">Buy</asp:LinkButton>
</ItemTemplate>
<edititemtemplate>
<asp:Textbox runat="server" id="txt"/>
<edititemtemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Is it possible to edit the GridView without the edititem Template?

I have done this before and I can only explain what I did
To make sure my edit controls is part of viewstate I added an empty form to the bottom of my page
<div id="myeditform">
<table>
<tr>
<td><asp:HiddenField runat="server" ID="myRowId" />
</td>
<td>... other controls </td>
<td>... Save button -- </td>
</tr>
<table>
</div>
The tr(s) has to match the number of columns in your grid or you can use colspan
Then
use jQuery or javascript to get the row (e.g. the nearest parent to the edit link clicked),
get the td(s) and pass the value of each td to the respective control in your edit form.
replace your <tr> with the content of the table in your edit form
when save is clicked, refresh the page to update gridview

Related

I want to Make my Gridview row vertical (like one row details after another)

I have a Gridview in asp.net which have some column.Now i want to show my result in Gridview in such a way that my first row header,below this row's each column details. After showing all the details in my row then i want to show another row below with columns of that row .
How can i do that ?
I just add the picture which i think will help to understand.
image here
Convert one of the columns to TemplateField, then inside the ItemTemplate for this field add controls for the rest of the properties, for example:
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="False" DataKeyNames="CustomerId">
<Columns>
<asp:TemplateField HeaderText="" InsertVisible="False" SortExpression="CustomerId">
<ItemTemplate>
<table>
<tr>
<td><strong>Id</strong></td>
<td><asp:Label ID="Label2" runat="server" Text='<%# Bind("CustomerName") %>'></asp:Label></td>
</tr>
<tr>
<td><strong>Name</strong></td>
<td><asp:Label ID="Label4" runat="server" Text='<%# Bind("CustomerName") %>'></asp:Label></td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
In the previous code I used a table to wrap the controls just to show the idea, but you can use bootstrap, html, css , javascript code inside it.

how to add two controls in template field and make second control in the right aligned in the next align

i have one template field . in that i have two controls text box and label control . i want to align label control in the bottom right of the column in the grid view.
<asp:TemplateField HeaderText="ITEM CODE / DESCRIPTION">
<ItemTemplate>
<table>
<tr><td><%#Eval("ItemCodeandDescription")%></td></tr>
<tr> <td style="text-align:right"><asp:Label ID="Label1" Text="VAT # 5%" runat="server"/></td></tr>
</table>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtCountry" runat="server" Text='<%# Eval("ItemCodeandDescription") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>

Display multiline in Repeater Control?

I am creating a Facebook Wall like structure and used repeater control for that using C#-Visual Studio 2010 amd Sql Server 2005 as database.
I am unable to display multiline text in repeater control
Script
<asp:TextBox ID="TextBox1" runat="server" Width="100%" TextMode="MultiLine"></asp:TextBox>
<asp:Repeater ID="myrepeater" runat="server">
<HeaderTemplate>
<table width="100%" style="font: 8pt verdana">
<tr style="background-color:#3C78C3">
<th>SCRAPS</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%#DataBinder.Eval(Container,"DataItem.scraps") %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
So, When I click on submit button, text stores in DataItem.scraps (which is column in my database table) and displays in repeater control.
But when I am inputting multiline Text in Textbox, it is displayed singleline in repeater control.
I want it to be displayed multiline repeater control.
So what is the problem exactly
1) Is it storing singleline text in database
2) or, repeater control problem
And, how to resolve it?
Please help me.
Thanks in advance,
Nikhil
The repeater control is pretty straight forward. There is no reason you can't control your output very thoroughly, just put everything in your item template:
<asp:Repeater ID="rptWall" runat="server">
<HeaderTemplate>
<h1>The wall<h1>
</HeaderTemplate>
<ItemTemplate>
<hr>
<asp:TextBox id="txtPost" runat="server" textmode="multiline" text='<%#DataBinder.Eval(Container.DataItem, "Posttext")%>'></asp:TextBox>
<hr>
</ItemTemplate>
<FooterTemplate>
<h3>put stuff here to add post</h3>
</FooterTemplate>
</asp:Repeater>

GridView edit command button with jquery

I want to use the gridview command button (edit) with the jquery not postback. Please help me.
Place an asp button in another item template and set its CommandName property to edit. This will work simillar to default edit button in grid view. Then you can call javascript function and perform your logic.
See the code below:
Remove the following line to avoid default edit button:
<asp:CommandField ShowEditButton="true" ShowCancelButton="true"/>
Add the following instead:
<asp:TemplateField HeaderText="headerName" >
<ItemTemplate>
<asp:Button ID="Button1" CommandName="edit" runat="server" Text="Button" />
</ItemTemplate>
</asp:TemplateField>
Hope this helps you..
I think you can do it in a gridview.What you need is to columns with textbox and display the data in the textbox and needs a button at the end .
<asp:TemplateField >
<HeaderTemplate>
Values
</HeaderTemplate>
<ItemTemplate>
<asp:textbox ID"txt" runat="server" cssclass="abc" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Spares">
<HeaderTemplate>
Edit column
</HeaderTemplate>
<ItemTemplate>
<asp:button id="abc" runat="server" text="save" cssclass="pqr" />
<input type="hidden" runat="server" value="" />
</ItemTemplate>
</asp:TemplateField>
Store the Id in a hidden field and it is possible to get the value of text box and hidden feild via jquery.
gridview will be rendered as html table and using parent() we can able to find the clicked row and after finding the row u can use find() to find the values in the txtbox and hidden feild. Use $ajax() or $post() to send data to server.

gridview not visible in updatepanel in ASP.NET

I currently have a GridView in a pop-up control. The GridView is embedded in an UpdatePanel and I have the window pop-up showing nothing on it. However, when I debug through it I see that the GridView has data in it and it is bound, but I am not noticing any changes. I even tried to call the Update method on the UpdatePanel, but received no changes in that either.
Basically what I wish to do is show a blank page up until my data has been loaded in. After the GridView has the data bound to it I would like it to be visible. Please find the below code snippet of the current process.
ASPX source:
<dx:ASPxPopupControl ID="ASPxPopupItem" runat="server" ClientIDMode="AutoID" LoadingPanelImagePosition="Bottom"
Modal="True" PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter"
EnableAnimation="False" HeaderText="Item Checker"
Width="614px">
<ContentCollection>
<dx:PopupControlContentControl ID="PopupCoverageItem" runat="server" SupportsDisabledAttribute="True">
<table style="width: 611px" cellpadding="3" cellspacing="3">
<tr>
<td align="center">
Title
</td>
</tr>
<tr>
<td colspan="2">
<div style="height: 75px; overflow: auto; width: 595px;">
<asp:UpdatePanel runat="server" ID="udpItems" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView runat="server" ID="gvTitles" Width="575px" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="90px">
<ItemTemplate>
<center>
<asp:ImageButton OnClick="btnSelect_Click" ID="lnk_Select" runat="server" CommandArgument='<%# Eval("title") %>'
ImageUrl="~/images/save.png" ToolTip="Choose this record" />
</center>
</ItemTemplate>
<HeaderStyle Width="90px"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:BoundField HeaderText="Item ID" DataField="item_id" SortExpression="item_id" />
<asp:BoundField HeaderText="Title" DataField="title" SortExpression="title" />
<asp:BoundField HeaderText="Date" DataField="date" SortExpression="date" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</td>
</tr>
<tr>
<td align="center">
<asp:Button runat="server" ID="btnCancelTitle" Text="Cancel" CssClass="popupButton"
OnClick="btnCancelTitle_Click" />
</td>
</tr>
</table>
</dx:PopupControlContentControl>
</ContentCollection>
</dx:ASPxPopupControl>
C# back end:
// Bind the data from the returning SQL query and update
gv.DataSource = npgDat;
gv.DataBind();
udpItems.Update();
Unfortunately there isn't much more of the C# back-end that I can show since we're using a company specific Query tool that works well in other situations.
Thanks
Are you sure an ASPxPopupControl supports having an UpdatePanel as content? I'd try getting rid of the UpdatePanel and see if the GridView works as expected then, or try moving the UpdatePanel (with the GridView still inside it) outside of the ASPxPopupControl and see if that works. If the problem is having the UpdatePanel inside the ASPxPopupControl, then you'll probably have to contact DevExpress for more help, as that would lead me to believe it's a problem with their control.
Update
Based on your comment below, you may want to look into Example: How to show the ASPxLoadingPanel while the content is loading inside the ASPxPopupControl over on the DevExpress support forum.

Categories

Resources