I am creating a gridview from SQL server in C#. Stored procedures are working just great. But now that I created the gridview and compiling. It is not even showing!
I've made quite a few times this, but now, I am unable to find out why it is not even showing.
This is my front.
<table cellpadding="2" cellspacing="0" border="0" width="100%" runat="server" id="tblVacantes">
<tr>
<td>
<asp:GridView ID="gvApplicants" runat="server" AllowPaging="True" AllowSorting="true"
AutoGenerateColumns="False" DataKeyNames="Id" CellPadding="5" ForeColor="#333333"
GridLines="None" PageSize="25" ShowFooter="True" Width="100%" Font-Size="9pt"
OnSorting="gvApplicants_Sorting" OnPageIndexChanging="gvApplicants_PageIndexChanging"
OnRowDataBound="gvApplicants_RowDataBound" EnablePersistedSelection="true">
<Columns>
<asp:BoundField HeaderText="Id" ReadOnly="True"
SortExpression="Id" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Top" />
<asp:BoundField DataField="Name" HeaderText="Name" ReadOnly="True"
SortExpression="Name" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Top" />
<asp:TemplateField HeaderText="Options" SortExpression="">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
<ItemTemplate>
<%# GetOpciones(Eval("username").ToString())%>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Username" HeaderText="Username"
SortExpression="Username" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" ItemStyle-VerticalAlign="Top" />
</Columns>
<AlternatingRowStyle BackColor="Beige" Height="32px"/>
<RowStyle BackColor="White" Height="32px" />
<FooterStyle BackColor="#780C28" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#780C28" Font-Bold="False" ForeColor="White" HorizontalAlign="Left" />
<PagerSettings Mode="NumericFirstLast" PageButtonCount="20" Position="Bottom" />
<PagerStyle CssClass="pagination" VerticalAlign="Middle" HorizontalAlign="Center" />
<SortedAscendingCellStyle BackColor="#FDF5AC" />
<SortedAscendingHeaderStyle BackColor="#4D0000" />
<SortedDescendingCellStyle BackColor="#FCF6C0" />
<SortedDescendingHeaderStyle BackColor="#820000" />
</asp:GridView>
</td>
</tr>
</table>
This is where I create all of my logic, where I store my SQL results in a list, where I plan to display them in the Grid. I have all getters and setters for ID, Nombre, Username and such.
public void LoadData()
{
gvApplicants.DataSource = GetApplicants();
gvApplicants.DataBind();
}
private List<ASF.Raffle.Entity.Staff> GetApplicants()
{
ASF.Raffle.BO.Staff dbCandidatos = new ASF.Raffle.BO.Staff();
List<ASF.Raffle.Entity.Staff> candidatos;
List<ASF.Raffle.Entity.Staff> candidatosFiltered = new List<ASF.Raffle.Entity.Staff>();
//primero filtro activos e inactivos.
return candidatos = dbCandidatos.GetAll();
}
protected string GetOpciones(string username)
{
ASF.Raffle.BO.Staff usr = new ASF.Raffle.BO.Staff();
ASF.Raffle.Entity.Staff u = usr.GetByUsername(username);
return usr.getAllOptions(u.Username);
}
public List<Entity.Staff> GetAll()
{
List<Entity.Staff> empleados = new List<Entity.Staff>();
//SQL Command para llamar el stored procedure
SqlCommand comando = new SqlCommand("dbo.[Empleados_GetAll]", base.Db);
//Ejecuta consulta
DataTable dtItem = base.Execute(comando);
//Transforma el Datatable en una lista de ResponsableFinancieros.
foreach (DataRow dr in dtItem.Rows)
empleados.Add(GetFromDataRow(dr));
return empleados;
}
But it is not even showing the table or throwing a connection error or anything related.
Thanks.
Thing is, I was missing a LoadData() method in the page_load. Therefore, it is now showing eveything correct now.
Related
I'd like to send gridview rows to an email on button press. The number of rows selected vary and use check boxes.
Background:
The app consists of 2 GridViews. One acts as a schedule, the other acts as a holding area for items taken out of the schedule. Included below is what I use to move Items out of the schedule. The code to put items back into schedule is identical, so it was not included.
The email function is to notify the user what specific items were taken out/put into schedule.
GridView1
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="ID" AllowPaging="True" ShowHeaderWhenEmpty="True" BackColor="White" BorderColor="#003399" BorderStyle="None" BorderWidth="1px" CellPadding="4" OnPageIndexChanging="GridView1_PageIndexChanging" Width="450px">
<Columns>
<asp:BoundField DataField="VEH_SER_NO" SortExpression="VEH_SER_NO" ReadOnly="True">
<ItemStyle HorizontalAlign="Center" Width="75px" Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="DATE_BLD_RATE" SortExpression="DATE_BLD_RATE" ReadOnly="True" DataFormatString="{0:yyyy/MM/dd}">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="SEQ" SortExpression="SEQ" ReadOnly="True">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="SV_TYPE_CD" SortExpression="SV_TYPE_CD" ReadOnly="True" Visible="False" />
<asp:BoundField DataField="COMMENT" SortExpression="COMMENT" Visible="False" ReadOnly="False" />
<asp:TemplateField HeaderText="Select" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="chkSel" runat="server" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#99CCCC" ForeColor="White" HorizontalAlign="center" />
<RowStyle BackColor="White" ForeColor="#003399" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<SortedAscendingCellStyle BackColor="#EDF6F6" />
<SortedAscendingHeaderStyle BackColor="#0D4AC4" />
<SortedDescendingCellStyle BackColor="#D6DFDF" />
<SortedDescendingHeaderStyle BackColor="#002876" />
</asp:GridView>
Code:
protected void cmdMoveRight_Click(object sender, EventArgs e)
{
if (drpReason0.SelectedValue != "" && drpReason.SelectedValue != "")
{
string strSQL = "SELECT VEH_SER_NO, DATE_BLD_RATE, SEQ, SV_TYPE_CD, COMMENT FROM Schedule " +
"WHERE Schedule.id = #ID";
MoveRows(GridView1, strSQL);
}
}
void MoveRows(GridView gv, string strSQL)
{
foreach (GridViewRow OneRow in gv.Rows)
{
CheckBox ckBox = OneRow.FindControl("cHkSel") as CheckBox;
if (ckBox.Checked)
{
int PKID = (int)gv.DataKeys[OneRow.RowIndex]["ID"];
SqlCommand cmdSQL = new SqlCommand(strSQL);
cmdSQL.Parameters.Add("#ID", SqlDbType.Int).Value = PKID;
SqlRun(cmdSQL);
}
}
LoadGrids();
}
public void SqlRun(SqlCommand cmdSQL)
{
using (SqlConnection conn = new SqlConnection(cs))
{
using (cmdSQL)
{
cmdSQL.Connection = conn;
conn.Open();
cmdSQL.ExecuteNonQuery();
}
}
}
I'm applying edit functionality on grid view with object data source.I want to take previous value when i click edit button that's need for another purpose here i'm trying to write code but it gives current value.how to get previous value.......hope you can help me
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = (GridView1.Rows[e.RowIndex] as GridViewRow);
string totalQuantity = (row.Cells[5].Controls[0] as TextBox).Text;//It gives current value but i want previous value
string totalPurchasePrice = (row.Cells[6].Controls[0] as TextBox).Text; //It gives current value but i want previous value
GridView1.EditIndex = -1;
//value store in session start
Session["totalQuantity"] = totalQuantity;
Session["totalPurchasePrice"] = totalPurchasePrice;
//value store in session end
}
and grid view code
<asp:GridView ID="GridView1" runat="server" CssClass="dataGridTable" AutoGenerateColumns="False" Width="100%" AllowPaging="True" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataSourceID="ObjectDataSource1" HeaderStyle-Height="30" OnRowCreated="GridView1_RowCreated" PageSize="30" DataKeyNames="invoiceNumber,productName,productCategory" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnRowUpdating="GridView1_RowUpdating">
<Columns>
<asp:CommandField ShowEditButton="true" ShowSelectButton="True" />
<asp:CommandField ShowDeleteButton="true"/>
<asp:BoundField DataField="invoiceNumber" HeaderText="Invoice" ReadOnly="true" SortExpression="invoiceNumber" />
<asp:BoundField DataField="productName" HeaderText="Name" ReadOnly="true" SortExpression="productName" />
<asp:BoundField DataField="productCategory" HeaderText="Category" ReadOnly="true" SortExpression="productCategory" />
<asp:BoundField DataField="totalQuantity" HeaderText="Quantity" SortExpression="totalQuantity" />
<asp:BoundField DataField="totalPurchasePrice" HeaderText="Total Price" SortExpression="totalPurchasePrice" />
<asp:BoundField DataField="salePricePerItem" HeaderText="Sale Price/Item" SortExpression="salePricePerItem" />
<asp:BoundField DataField="comments" HeaderText="Comments" SortExpression="comments" />
<asp:BoundField DataField="date" HeaderText="Date" ReadOnly="true" SortExpression="date" />
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" Height="24px" ImageUrl="~/Images/detailsInfo.png" Width="24px" OnClick="ImageButton1_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" CssClass="gridHeaderAlignment" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<RowStyle ForeColor="#000066" HorizontalAlign="Center" VerticalAlign="Middle" />
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#007DBB" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#00547E" />
</asp:GridView>
I would to add the selected rows from gridview into another gridview. Could someone help me on this? When I try to bind gridview to another gridview, another gridview doesn't appear.
The aspx file I posted below is about how I created the gridview. The gridview1 will get its gridview contents from the database table. While the cs file is about how I am going to bind selected rows from gridview1 into gridview2. The problem now is when I try to bind the rows over, the gridview2 didn't appear, only gridview1 appeared.
This is my codes:
ASPX file:
<h3 class="h3">Grid View1</h3>
<div style="width: 100%; height: 400px; overflow: auto">
<asp:GridView ID="GridView1"
runat="server"
AllowSorting="True"
AutoGenerateColumns="False"
Width="100%"
CellPadding="6"
ForeColor="#333333"
GridLines="Horizontal"
BorderColor="Black"
BorderStyle="Solid"
BorderWidth="2px"
EmptyDataText="Record Not Found"
OnRowDataBound="GridView1_OnRowDataBound">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="DATE"
HeaderText="DATE"></asp:BoundField>
<asp:BoundField DataField="CODE"
HeaderText="CODE"></asp:BoundField>
<asp:BoundField DataField="PROFILE_NAME"
HeaderText="PROFILE_NAME"></asp:BoundField>
<asp:BoundField DataField="DESCRIPTION"
HeaderText="DESCRIPTION"></asp:BoundField>
<asp:BoundField DataField="STATUS"
HeaderText="STATUS"></asp:BoundField>
<asp:BoundField DataField="USER"
HeaderText="USER"></asp:BoundField>
<asp:BoundField DataField="SUB_USER"
HeaderText="SUB_USER"></asp:BoundField>
<asp:BoundField DataField="SCORE"
HeaderText="SCORE"></asp:BoundField>
<asp:BoundField DataField="ROLE"
HeaderText="ROLE"></asp:BoundField>
<asp:BoundField DataField="QUANTITY"
HeaderText="QUANTITY"></asp:BoundField>
<asp:BoundField DataField="ITEM"
HeaderText="ITEM"></asp:BoundField>
<asp:BoundField DataField="PRICE"
HeaderText="PRICE"></asp:BoundField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1"
Font-Bold="False"
ForeColor="Black" />
<HeaderStyle BackColor="#507CD1"
Font-Bold="False"
ForeColor="Black"
BorderStyle="Solid"
BorderWidth="2px" />
<PagerStyle BackColor="#2461BF"
ForeColor="White"
HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1"
Font-Bold="False"
ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
<h3 class="h3">Grid View2</h3>
<div style="width: 100%; height: 400px; overflow: auto">
<asp:GridView ID="GridView2"
runat="server"
AllowSorting="True"
AutoGenerateColumns="False"
Width="100%"
CellPadding="6"
ForeColor="#333333"
GridLines="Horizontal"
BorderColor="Black"
BorderStyle="Solid"
BorderWidth="2px"
EmptyDataText="Record Not Found"
OnRowDataBound="GridView2_OnRowDataBound">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="DATE"
HeaderText="DATE"></asp:BoundField>
<asp:BoundField DataField="CODE"
HeaderText="CODE"></asp:BoundField>
<asp:BoundField DataField="PROFILE_NAME"
HeaderText="PROFILE_NAME"></asp:BoundField>
<asp:BoundField DataField="DESCRIPTION"
HeaderText="DESCRIPTION"></asp:BoundField>
<asp:BoundField DataField="STATUS"
HeaderText="STATUS"></asp:BoundField>
<asp:BoundField DataField="USER"
HeaderText="USER"></asp:BoundField>
<asp:BoundField DataField="SUB_USER"
HeaderText="SUB_USER"></asp:BoundField>
<asp:BoundField DataField="SCORE"
HeaderText="SCORE"></asp:BoundField>
<asp:BoundField DataField="ROLE"
HeaderText="ROLE"></asp:BoundField>
<asp:BoundField DataField="QUANTITY"
HeaderText="QUANTITY"></asp:BoundField>
<asp:BoundField DataField="ITEM"
HeaderText="ITEM"></asp:BoundField>
<asp:BoundField DataField="PRICE"
HeaderText="PRICE"></asp:BoundField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1"
Font-Bold="False"
ForeColor="Black" />
<HeaderStyle BackColor="#507CD1"
Font-Bold="False"
ForeColor="Black"
BorderStyle="Solid"
BorderWidth="2px" />
<PagerStyle BackColor="#2461BF"
ForeColor="White"
HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1"
Font-Bold="False"
ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
CS file:
protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (Convert.ToString(DataBinder.Eval(e.Row.DataItem, “USER”)) == “ALAN TAN”)
{
DataTable dt = new DataTable();
dt.Columns.Add(“DATE”);
dt.Columns.Add(“CODE”);
dt.Columns.Add(“PROFILE_NAME”);
dt.Columns.Add(“DESCRIPTION”);
dt.Columns.Add(“STATUS”);
dt.Columns.Add(“USER”);
dt.Columns.Add(“SUB_USER”);
dt.Columns.Add(“SCORE”);
dt.Columns.Add(“ROLE”);
dt.Columns.Add(“QUANTITY”);
dt.Columns.Add(“ITEM”);
dt.Columns.Add(“PRICE”);
DataRow dataRow;
dataRow = dt.NewRow();
int i2 = 1;
for(int i=0; i<dataRow.Table.Columns.Count; i++)
{
dataRow[i] = GridView1.SelectedRow.Cells[i2].Text;
i2++;
}
dt.Rows.Add(dataRow);
GridView2.DataSource = dt;
GridView2.DataBind();
}
}
}
Any help is greatly appreciated. Thanks!
I Really didn't understand messy code done by you (Too many things are missing in your question). Refer below links that will explain you will example.
http://www.aspsnippets.com/Articles/Transfer-Selected-Rows-from-one-GridView-to-Another-in-Asp.net.aspx
http://www.ittutorials.in/source/aspDotnet/scf13/move-gridview-rows-from-one-gridview-to-another.aspx
Updates:
dt.Rows.Add() must be inside of for loop so everytime it will get add new row.
try to update following code in cs file
for(int i=0; i<dataRow.Table.Columns.Count; i++)
{
dt.Rows.Add(GridView1.SelectedRow.Cells[i2].Text);
i2++;
}
GridView2.DataSource = dt;
GridView2.DataBind();
I am trying to get the selected row data and transfer it to a label on the same page. However I cannot get the Gridview.SelectedRow to work with my CommandName. I have tried everything....
I get the error. Object reference not set to an instance of an object. on Label2.Text
Here is my Code:
protected void GridView1_RowCommand(Object sender, GridViewCommandEventArgs e)
{
// If multiple ButtonField column fields are used, use the
// CommandName property to determine which button was clicked.
if (e.CommandName == "Grab")
{
Label2.Text = GridView1.SelectedRow.Cells[2].Text;
Label3.Text = GridView1.SelectedRow.Cells[3].Text;
Label4.Text = GridView1.SelectedRow.Cells[4].Text;
Label5.Text = GridView1.SelectedRow.Cells[5].Text;
}
}
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" DataKeyNames="ID" DataSourceID="SqlDataSource1" ForeColor="Black" GridLines="Vertical" CssClass="td" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" Width="574px" onrowcommand="GridView1_RowCommand">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Action">
<ItemTemplate>
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/images/edit.png" OnClick="ImageButton2_Click" />
<asp:ImageButton ID="ImageButton1" runat="server" CommandName="Select" ImageUrl="~/images/delete.png" onclientclick=" return confirm('Are you want to Delete this Vehicle?');" />
<asp:ImageButton ID="ImageButton3" runat="server" ImageUrl="~/images/refre.png" CommandName="Grab" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Year" HeaderText="Year" SortExpression="Year" />
<asp:BoundField DataField="Make" HeaderText="Make" SortExpression="Make" />
<asp:BoundField DataField="Model" HeaderText="Model" SortExpression="Model" />
<asp:BoundField DataField="Submodel" HeaderText="Submodel" SortExpression="Submodel" />
<asp:BoundField DataField="ISENABLED" HeaderText="ISENABLED" SortExpression="ISENABLED" />
</Columns>
<FooterStyle BackColor="#CCCC99" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<RowStyle BackColor="#F7F7DE" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#FBFBF2" />
<SortedAscendingHeaderStyle BackColor="#848384" />
<SortedDescendingCellStyle BackColor="#EAEAD3" />
<SortedDescendingHeaderStyle BackColor="#575357" />
</asp:GridView>
Try something like this. Since you're trying to access the values in the command event and not in the OnSelectedIndexChanged event you need to get hold of the row triggering the command event first.
if (e.CommandName == "Grab")
{
GridViewRow row = (GridViewRow)((ImageButton)e.CommandSource).NamingContainer;
if (row != null)
{
Label2.Text = row.Cells[2].Text;
Label3.Text = row.Cells[3].Text;
Label4.Text = row.Cells[4].Text;
Label5.Text = row.Cells[5].Text;
}
}
I have a GridView that is built from a Linq query as follows
var GridViewLoad = from d in QVuser.QlikViewDashboards.AsEnumerable()
join p in tempPermissions.AsEnumerable() on d.DashboardId equals Convert.ToInt32(p["DashboardId"])
where Convert.ToInt32(p["UserId"]) == GridViewUser
select new
{
DashboardId = d.DashboardId,
PermissionId = Convert.ToInt32(p["PermissionId"]),
DashboardName = d.DashboardName,
Operational_Unit = p["Operational_Unit"].ToString(),
Cost_Centre = p["Cost_Centre"].ToString(),
Project = p["Project"].ToString(),
Fund = p["Fund"].ToString()
};
GridView1.DataSource = GridViewLoad;
GridView1.DataKeyNames = new string[] {"PermissionId"};
GridView1.DataBind();
Then the GridView is defined as:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="3"
GridLines="Vertical" ShowHeaderWhenEmpty="True" OnRowDeleting="GridView1_RowDeleting"
style="text-align: center" BackColor="White" BorderColor="#999999"
BorderStyle="None" BorderWidth="1px" Width="550px"
>
<AlternatingRowStyle BackColor="#DCDCDC" />
<Columns>
<asp:TemplateField HeaderText="Delete" ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="false"
CommandArgument='<%# Eval("PermissionId") %>' CommandName="Delete" Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="PermissionId" HeaderText="ID"/>
<asp:BoundField DataField="DashboardName" HeaderText="Dashboard" ReadOnly="True" SortExpression="DashboardName" />
<asp:BoundField DataField="Operational_Unit" HeaderText="Operational_Unit" ReadOnly="True" SortExpression="Operational_Unit" />
<asp:BoundField DataField="Cost_Centre" HeaderText="Cost_Centre" ReadOnly="True" SortExpression="Cost_Centre" />
<asp:BoundField DataField="Fund" HeaderText="Fund" ReadOnly="True" SortExpression="Fund" />
<asp:BoundField DataField="Project" HeaderText="Project" ReadOnly="True" SortExpression="Project" />
</Columns>
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" BorderStyle="Solid" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" BorderStyle="Solid"
BorderWidth="1px" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#0000A9" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#000065" />
What I want to do is hide the PermissionId field from sight, but it obviously still needs to be there for the Delete button to work..
Can someone help me out with this?
I've tried setting Visible="false", which hides it, but then my delete button stops working..
Cheers for your help..
Since you're setting the DataKeyNames, you should be able to retrieve the permission ID from the index of the row being deleted, like so:
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int permissionId = (int)GridView1.DataKeys[e.RowIndex].Value;
DoDelete(permissionId);
}
This should work whether the column is visible or not.
Try
<asp:BoundField DataField="PermissionId" HeaderText="ID" Visible="False"/>