Transferring data from Database to multiple pages after selecting Gridview row - c#

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>

Related

Why my gridview is not getting expanded?

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.

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

upload multiple radgrids to single excel sheet with formatting options

I want to upload 3radgrids to a single excel and that too in same sheet on a button click.
Like one table contents followed by other, and so on.
In between i need to add Headings other than the column headers for the contents,
Can anyone help me in this regard.
Protected void buttonclick(object o,sender s)
{
RadGrid1.ExportSettings.Excel.Format = (GridExcelExportFormat)Enum.Parse(typeof(GridExcelExportFormat), alternateText);
RadGrid1.ExportSettings.IgnorePaging = CheckBox1.Checked;
RadGrid1.ExportSettings.ExportOnlyData = true;
RadGrid1.ExportSettings.OpenInNewWindow = true;
RadGrid1.MasterTableView.ExportToExcel();
}
Add(your 3 grids) inside a dummy parent grid. Name the dummy radgrid as GridMain and export GridMain
Please look at the following code
<telerik:RadGrid ID="GridMain" runat="server" Skin="Default" ShowHeader="false" OnNeedDataSource="GridMain_NeedDataSource"
BorderStyle="None" Width="500px">
<MasterTableView>
<ItemTemplate>
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"
Skin="Vista">
<MasterTableView AutoGenerateColumns="false">
<Columns>
<telerik:GridBoundColumn HeaderText="ID" UniqueName="ID" DataField="ID" />
</Columns>
</MasterTableView>
</telerik:RadGrid>
<telerik:RadGrid ID="RadGrid2" runat="server" OnNeedDataSource="RadGrid2_NeedDataSource"
Skin="Vista">
<MasterTableView AutoGenerateColumns="false">
<Columns>
<telerik:GridBoundColumn HeaderText="Description" UniqueName="Description" DataField="Description" />
</Columns>
</MasterTableView>
</telerik:RadGrid>
</ItemTemplate>
</MasterTableView>
</telerik:RadGrid>
There is forum post in telerik site, which talks about this issue.
Check it out Exporting Multiple Radgrids
Note: Simply leave blank in need data source

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" />

How do I make the gridview headers to links?

I want the headers of my gridview to be hyperlinks, without the "SortExpression"...
I searched the net, but I've been not very succesful.
Anyone has the solution?
For example: when clicking on the header of a simple gridview, the site navigates to a webpage. Is it possible?
Thanks in advance!
Have you tried Gridview Header template like...
<asp:GridView runat="server" ID="grd">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:HyperLink runat="server" NavigateUrl="YourURL"> </asp:HyperLink>
</HeaderTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I think a HeaderTemplate is needed here...
Ref.: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.templatefield.headertemplate.aspx
HTH.
Now I got this gridview, And I need the headers to be clickable, whereafter an event starts (something like OnClickHeader="header_ClickEvent"?) Ofcourse there is a SortExpression element, which enables to sort the grid, but I want to be able to start any event, like when clicking a button.
I could not find any solution within the asp:BoundField nor asp:TemplateField...
I thought a hyperlink could solve the problem, but that was a bit premature.
The Gridview:
<asp:GridView CssClass="gridview" ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="Student_key" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" PagerSettings-Visible="false" PageSize="14">
<HeaderStyle CssClass="headerstyle" />
<RowStyle CssClass="rowstyle"/>
<AlternatingRowStyle CssClass="altrowstyle" />
<Columns>
<asp:BoundField DataField="Studentnumber" HeaderText="Studentnummer" >
<HeaderStyle CssClass="header100" />
</asp:BoundField>
<asp:BoundField DataField="Prefix" HeaderText="Voorletters" >
<HeaderStyle CssClass="header75" />
</asp:BoundField>
<asp:BoundField DataField="prename" HeaderText="Voornaam" SortExpression="Voornaam">
<HeaderStyle CssClass="header75" />
</asp:BoundField>
<asp:BoundField DataField="nickname" HeaderText="Roepnaam" >
<HeaderStyle CssClass="header100" />
</asp:BoundField>
<asp:BoundField DataField="insertion" HeaderText="Tussenvoegsel" >
<HeaderStyle CssClass="header100" />
</asp:BoundField>
<asp:BoundField DataField="surname" HeaderText="Achternaam">
<HeaderStyle CssClass="header100" />
</asp:BoundField>
<asp:CommandField SelectText="show results" ShowSelectButton="True" >
<HeaderStyle CssClass="header100" />
</asp:CommandField>
</Columns>
<EmptyDataTemplate >There are no results shown, please try again.</EmptyDataTemplate>
</asp:GridView>
I used a method that might be a little unconventional but it works. In my case I wanted to use the standard BoundField controls in my gridview as opposed to using a template field with both a HeaderTemplate and ItemTemplate. I used a simple gridview based on a SQL datasource that looks like this.
<asp:GridView
ID="gvTopXByContest"
runat="server"
AutoGenerateColumns="False"
DataSourceID="dsTopXByContest"
AllowSorting="true"
OnSorting="gvTopXByContest_OnSorting" >
<Columns>
<asp:BoundField DataField="txtOnlineUserName" HeaderText="Fan Name & Rank" SortExpression="txtOnlineUserName" ItemStyle-Width="155px"></asp:BoundField>
<asp:BoundField DataField="fltTotalPoints" HeaderText="Points" SortExpression="fltTotalPoints" ItemStyle-Width="40px"></asp:BoundField>
<asp:BoundField DataField="curWon" HeaderText="Won" SortExpression="curWon" ItemStyle-Width="40px"></asp:BoundField>
</Columns>
</asp:GridView>
I then used code that fires on the OnSorting event of the gridview to do my redirects
Protected Sub gvTopXByContest_OnSorting(sender As Object, e As GridViewSortEventArgs)
If e.SortExpression <> DirectCast(sender, GridView).SortExpression Then
If e.SortExpression = "txtOnlineUserName" Then
Response.Redirect(URL to redirect to goes here)
ElseIf e.SortExpression = "fltTotalPoints" Then
Response.Redirect(URL to redirect to goes here)
Else
'I could have used another ElseIf here but since there are only 3 columns Else works
Response.Redirect(URL to redirect to goes here)
End If
End Sub

Categories

Resources