16,019,514 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Visual Basic questions
View Javascript questions
View .NET questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Emmanuel Constant MSSM (Top 4 by date)
Emmanuel Constant MSSM
18-Oct-13 11:37am
View
I received the same results after commenting out the "GridView1.DataBind();"
Emmanuel Constant MSSM
17-Oct-13 16:00pm
View
Hi again JoCodes,
I tried using the solution you provided
but I have the same results.
Code Behind (Row_editing):
public void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
((TemplateField)GridView1.Columns[1]).EditItemTemplate = null;
GridView1.DataBind();
Session["SelecetedRowIndex"] = e.NewEditIndex;
}
Gridview:
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" BackColor="#CCCCCC" BorderColor="White"
BorderStyle="Solid" BorderWidth="3px" CellPadding="4" DataKeyNames="EventID"
CellSpacing="2" ForeColor="Black" Width="984px" EmptyDataText="No Events Found"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnRowEditing ="GridView1_RowEditing">
<rowstyle backcolor="White">
<columns>
<asp:CommandField ButtonType="Button" CausesValidation="False"
DeleteText="" EditText="Add Track ID" InsertText="" NewText=""
SelectText="" ShowEditButton="True" UpdateText="Commit" />
<asp:CommandField ButtonType="Button"
DeleteText="" EditText="" InsertText="" NewText=""
SelectText="Export" UpdateText="" InsertVisible="False"
ShowCancelButton="False" ShowSelectButton="True" CancelText="" />
<asp:BoundField DataField="CME_Event_Track_ID" HeaderText="CME Track ID" SortExpression="CME_Event_Track_ID" />
<asp:BoundField DataField="Event_Type" HeaderText="Event Type" SortExpression="Event_Type" Visible="False" />
<asp:BoundField DataField="Event_Name" HeaderText="Event Name" SortExpression="Event_Name" />
<asp:BoundField DataField="Event_Desc" HeaderText="Event Desc" SortExpression="Event_Desc" />
<asp:BoundField DataField="EventDate" HeaderText="Event Date" SortExpression="EventDate" />
<asp:BoundField DataField="EventCount" HeaderText="Attendance Count" SortExpression="EventCount" />
<asp:BoundField DataField="MissingRFID" HeaderText="Number Of Missing RFID" SortExpression="MissingRFID" />
<footerstyle backcolor="#CCCCCC">
<PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
<emptydatatemplate>
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
Emmanuel Constant MSSM
16-Oct-13 10:03am
View
Code behind Continued:
exportSpreadsheet(dtExport, "ExportReport");
}
public static void exportSpreadsheet(DataTable dtTable, String strName)
{
HttpContext context = HttpContext.Current;
context.Response.Clear();
foreach (DataColumn column in dtTable.Columns)
{
context.Response.Write(column.ColumnName + ",");
}
context.Response.Write(Environment.NewLine);
foreach (DataRow drRow in dtTable.Rows)
{
for (int i = 0; i < dtTable.Columns.Count; i++)
{
context.Response.Write(drRow[i].ToString().Replace(",", string.Empty) + ",");
}
context.Response.Write(Environment.NewLine);
}
context.Response.ContentType = "text/csv";
context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + strName + ".csv");
context.Response.End();
}
Emmanuel Constant MSSM
16-Oct-13 10:00am
View
Grid:
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" BackColor="#CCCCCC" BorderColor="White"
BorderStyle="Solid" BorderWidth="3px" CellPadding="4" DataKeyNames="EventID"
CellSpacing="2" ForeColor="Black" Width="984px" EmptyDataText="No Events Found"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
<rowstyle backcolor="White">
<columns> <asp:CommandField ButtonType="Button" CausesValidation="False"
DeleteText="" EditText="Add Track ID" InsertText="" NewText=""
SelectText="" ShowEditButton="True" UpdateText="Commit" />
<asp:CommandField ButtonType="Button"
DeleteText="" EditText="" InsertText="" NewText=""
SelectText="Export" UpdateText="" InsertVisible="False"
ShowCancelButton="False" ShowSelectButton="True" CancelText="" />
<asp:BoundField DataField="CME_Event_Track_ID" HeaderText="CME Track ID" SortExpression="CME_Event_Track_ID" />
<asp:BoundField DataField="Event_Type" HeaderText="Event Type" SortExpression="Event_Type" Visible="False" />
<asp:BoundField DataField="Event_Name" HeaderText="Event Name" SortExpression="Event_Name" />
<asp:BoundField DataField="Event_Desc" HeaderText="Event Desc" SortExpression="Event_Desc" />
<asp:BoundField DataField="EventDate" HeaderText="Event Date" SortExpression="EventDate" />
<asp:BoundField DataField="EventCount" HeaderText="Attendance Count" SortExpression="EventCount" />
<asp:BoundField DataField="MissingRFID" HeaderText="Number Of Missing RFID" SortExpression="MissingRFID" />
<footerstyle backcolor="#CCCCCC">
<PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
<emptydatatemplate>
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CME_RFID %>" ProviderName="System.Data.SqlClient"
SelectCommand="SELECT * FROM CME_RFIDReader.vAdminExportStat order by Event_Date DESC"
UpdateCommand="UPDATE CME_RFIDReader.CME_Events SET CME_Event_Track_ID = @CME_Event_Track_ID WHERE EventID = @EventID">
Code Behind:
int RowCount;
protected void SearchEvent_Click(object sender, EventArgs e)
{
SqlDataSource1.FilterExpression = "Event_Name LIKE '%" + txtSearchEvent.Text + "%' or Event_Desc LIKE '%" + txtSearchEvent.Text + "%'";
GridView1.DataBind();
RowCount = GridView1.Rows.Count;
txtSearchEvent.Text = "";
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
int eventid;
eventid = Convert.ToInt32(GridView1.SelectedDataKey.Value);
String strCon = ConfigurationManager.ConnectionStrings["CME_RFID"].ConnectionString;
DataTable dtExport = new DataTable();
String strSQL = "SELECT PersonID, Person_Last, Person_First, Person_Title, Life_Number, Event_Name, EventID, CME_Event_Track_ID FROM CME_RFIDReader.vAttendanceList WHERE EventID = " + eventid;
SqlConnection connect = new SqlConnection(strCon);
SqlCommand command = new SqlCommand(strSQL, connect);
SqlDataAdapter adExport = new SqlDataAdapter(command);
adExport.Fill(dtExport);