Why my gridview is not getting expanded? - c#

I have a gridview which could display this kind of data,
Here the circled part is expected to be repeated. Now I want to put Maximize and minimize facility in GRIDVIEW. Rows with common CaseNo's should be collapsed and when I click + sign then it should expand common rows.
I tried buttons within template field etc but nothing works, I am new to development.
<asp:GridView runat="server" ID="grdviewCaseHearingsDetails" AllowPaging="true" PageSize="20" OnPageIndexChanging="grdviewCaseHearingsDetails_PageIndexChanging"
OnRowCommand="grdviewCaseHearingsDetails_RowCommand" PagerStyle-BackColor="#99CC99" HeaderStyle-BackColor="#99CC99" DataKeyNames="pk_CaseHearings_ID"
PagerStyle-Font-Size="12.5px" PagerStyle-ForeColor="Black" PagerStyle-HorizontalAlign="Center" AutoGenerateColumns="false" OnRowDataBound="grdviewCaseHearingsDetails_RowDataBound"
CssClass="table table-condensed table-bordered table-striped table-responsive scrollable">
<Columns>
<asp:BoundField DataField="pk_CaseHearings_ID" HeaderText="S.No" />
<asp:BoundField DataField="CaseNo" HeaderText="Case No" />
<asp:BoundField DataField="CasePetitioner" HeaderText="Petitioner" />
<asp:BoundField DataField="Responder" HeaderText="Responder" />
<asp:BoundField DataField="HearingDate" HeaderText="Hearing Date" />
<asp:BoundField DataField="OpeningDate" HeaderText="Initiation Date" />
<asp:BoundField DataField="ConcernedOfficeName" HeaderText="Concerned Office" />

You have to use nested gridview or gridview inside a repeater.
i prefer gridview nested in repeater. you can hide duplicate rows (tr's) on row created event of repeater on load and use javascript for show/Hide on '+' click.

Related

Transferring data from Database to multiple pages after selecting Gridview row

I have a GridView bound to a Database. I want to click a row and display data from the Database that are not in the GridView to 2 pages. I used the DataNavigationFields but that only display what is in the Gridview.
This is my code for the GridView
<asp:GridView ID="gvStock" CssClass="GV" runat="server" enablepagingandcallbackz="false" AutoGenerateColumns="False" AllowPaging="True" AllowSorting="True" OnSorting="OnSorting" OnPageIndexChanging="OnPageIndexChanging" PageSize="20">
<Columns>
<asp:HyperLinkField Text="View" DataNavigateUrlFields="pCode,pID,bCode,SBrand" DataNavigateUrlFormatString="ProductDetail.aspx?pCode={0}&pID={1}&bCode={2}&SBrand={3}/>
<asp:BoundField DataField="pCode" HeaderText="Product Code" />
<asp:BoundField DataField="pID" HeaderText="PID"/>
<asp:BoundField DataField="bCode" HeaderText="Bar Code"/>
<asp:BoundField DataField="SBrand" HeaderText="Brand"/>
</Columns>
</asp:GridView>

Stored Procedure some columns to gridview

I would like to apologize if this has been asked in a different way before. I couldn't find any links specific to this question.
I'm currently learning how to implement GridViews on an ASP.Net web forms application, changing to grid views from a repeater. The repeaters had been binding to some columns retrieved by a stored procedure on our SQL Server and then displaying to the page. Due to the large amount of data, we decided that using the paging feature associated with grid views would improve our performance. However, when I have the grid view bind to the data source, all of the columns from the stored procedure are displayed. I believe I have the syntax correct:
<asp:GridView ID="CECreditGridView" runat="server" DataSourceID="testSqlSource" AllowPaging="true" PageSize="100">
<Columns>
<asp:HyperLinkField DataNavigateUrlFormatString="CECredit_Detail.aspx?CECredit_ID={0}" DataNavigateUrlFields="CECredit_ID" ItemStyle-CssClass="actionLinkView" />
<asp:HyperLinkField DataNavigateUrlFormatString="CECredit_Update.aspx?CECredit_ID={0}" DataNavigateUrlFields="CECredit_ID" ItemStyle-CssClass="actionLinkEdit" />
<asp:HyperLinkField DataNavigateUrlFormatString="CECredit_Detail.aspx?CECredit_ID={0}" DataNavigateUrlFields="CECredit_ID" ItemStyle-CssClass="actionLinkDelete" />
<asp:BoundField HeaderText="ID" DataField="CECredit_ID"/>
<asp:HyperLinkField HeaderText="Session Title" DataNavigateUrlFormatString="CECredit_Detail.aspx?CECredit_ID={0}" DataNavigateUrlFields="CECredit_ID" DataTextField="CECredit_Name" />
<asp:HyperLinkField HeaderText="Person" DataNavigateUrlFormatString="Person_Update.aspx?Person_ID={0}" DataNavigateUrlFields="Person_ID" DataTextField="FullName" />
<asp:HyperLinkField HeaderText="Type" DataNavigateUrlFormatString=“CECreditType_Update.aspx?CECreditType_ID={0}" DataNavigateUrlFields="CECreditType_ID" DataTextField="CECreditType_Name" />
<asp:HyperLinkField HeaderText="Status" DataNavigateUrlFormatString="CECreditStatus_Update.aspx?CECreditStatus_ID={0}" DataNavigateUrlFields="CECreditStatus_ID" DataTextField="CECreditStatus_Name" />
<asp:BoundField HeaderText="Expiration Date" DataFormatString = "{0:MM/dd/yyyy}" DataField="CECredit_ExpirationDate" />
<asp:BoundField HeaderText="Last Updated" DataFormatString = "{0:MM/dd/yyyy}" DataField="CECredit_RecordUpdateDate" />
</Columns>
<PagerSettings Mode="NextPreviousFirstLast" FirstPageText="First" LastPageText="Last" NextPageText="Next" PreviousPageText="Previous" />
</asp:GridView>
So my question is, is there a way to only have the called columns display? Or will I need to change the stored procedure to only return the columns I want displayed? We were trying to have the stored procedure stay the same because the code behind used a few of the other columns for validation, etc.

Copy gridview cell value to the clipboard

I have a gridview with some values. If the user clicks on a link or button (here I took a Buttonfield with the text 'Copy') on one of the rows, it should copy a cell value of that row to the clipboard.
Is something like this possible in asp.net c# ?
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="id" DataSourceID="SqlDataSource1" Visible="False" OnRowDataBound="GridView1_RowDataBound"
onselectedindexchanged="GridView1_SelectedIndexChanged1">
<Columns>
<asp:BoundField DataField="Username" HeaderText="Username"
SortExpression="Username" />
<asp:BoundField DataField="Password" HeaderText="Password"
SortExpression="Password" />
<asp:CommandField ButtonType="Image" EditImageUrl="/images/edit.png" CancelImageUrl="/images/undo.png" UpdateImageUrl="/images/save.png" ShowEditButton="True" />
<asp:CommandField ButtonType="Image" ShowDeleteButton="True" DeleteImageUrl="/images/deletered.png" />
<asp:ButtonField Text="Copy" />
</Columns>
<EmptyDataTemplate>
No data available
</EmptyDataTemplate>
</asp:GridView>
There is no Onclick event available for a ButtonField. Otherwise I would think of using some javascript (I have seen that in other solutions)
Thanks for any input.
You can do that with windows form only, but since you are working on Web application you should write client side code which is javascript to copy data on client side not server side. checkout this link

Databind to gridview from backend c#, but show the fields only which is mentioned in BoundField of gridview

I am using the linq to fetch from database and bind in the gridview using the below code:
details.aspx.cs
var mlo1 = (from nmo2 in nmo.PrimaCustDetails1s select nmo2).ToList();
custdet.DataSource = mlo1;
custdet.DataBind();
details.aspx
<asp:GridView ID="custdet" runat="server">
</asp:GridView>
All the data from database will be shown.
I want to show only some fields from the table using Boundfield
<asp:GridView ID="custdet" runat="server">
<Columns>
<asp:BoundField DataField="CustAccNo" HeaderText ="AccNo" />
<asp:BoundField DataField="Name" HeaderText="Customer Name" />
</Columns>
</asp:GridView>
I don't want other fields... Can someone advise me on how to do this?
Set Gridview property AutoGenerateColumns="false"
<asp:GridView ID="custdet" AutoGenerateColumns="false" runat="server">
<Columns>
<asp:BoundField DataField="CustAccNo" HeaderText ="AccNo" />
<asp:BoundField DataField="Name" HeaderText="Customer Name" />
</Columns>
</asp:GridView>
Try adding the AutoGenerateColumns="false" attribute to the asp:GridView element
You can set autogenerate property of gridview columns to false Gridview Autogeneratecolumns Property
<asp:GridView AutoGenerateColumns="False" />

ASP.NET GridView using C#

I have a problem with gridview, I am using a gridview and listview on a page, when I select a row in the gridview I want to insert the data into the listview based on selection in the gridview. I am using a primary key in gridview.
PLease help me out
This is also called "Master-Detail".
You can find a great tutorial here.
In short, you need to make the row selectable.
<asp:GridView ID="ProductsGrid" runat="server"
AutoGenerateColumns="False" DataKeyNames="ProductID"
DataSourceID="AllProductsDataSource" EnableViewState="False">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="ProductName"
HeaderText="Product" SortExpression="ProductName" />
<asp:BoundField DataField="UnitPrice"
DataFormatString="{0:c}" HeaderText="Unit Price"
HtmlEncode="False" SortExpression="UnitPrice" />
</Columns>
</asp:GridView>
This is done with <asp:CommandField ShowSelectButton="True" /> in the code above.
The next step is to add you DetailsView to be binded to the selected element of the master gridview. This can be done because the selection return the primary key of the element, from there you can load the detail.
This do a PostBack, if you want you can use Ajax and remove the PostBack flickering.
I believe the select on the gridview should fire off the event SelectedIndexChanged(). You would use that event to create the datasource for your listview and then bind the datasource to your listview.

Categories

Resources