I have a gridview control on page data is showing perfectly fine. I add edit button in row to update record its also working fine until I add another link in next column which redirect me to new page.
Here is my Gridview code:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1" DataSourceID="SqlDataSource1" GridLines="None" DataKeyNames="issue_id,pro_id" OnRowCommand="GridView1_RowCommand">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:TemplateField HeaderText="Key#" InsertVisible="False" SortExpression="issue_id">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("issue_id") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="view" CommandArgument ='<%# Eval("issue_id") %>' Text='<%# Eval("issue_id") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="pro_id" HeaderText="pro_id" SortExpression="pro_id" ReadOnly="True" Visible="False" />
<asp:BoundField DataField="name" HeaderText="Project Name" SortExpression="name" />
<asp:BoundField DataField="type" HeaderText="Issue Type" SortExpression="type" />
<asp:BoundField DataField="summary" HeaderText="Summary" SortExpression="summary" />
<asp:BoundField DataField="mem_id" HeaderText="Member Name" SortExpression="mem_id" />
<asp:TemplateField HeaderText="Priority" SortExpression="priority">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>Major</asp:ListItem>
<asp:ListItem>Critical</asp:ListItem>
<asp:ListItem>Minor</asp:ListItem>
<asp:ListItem>Cosmetic</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("priority") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="status" HeaderText="Status" SortExpression="status" />
<asp:BoundField DataField="impact" HeaderText="Impact" SortExpression="impact" />
<asp:BoundField DataField="Expr1" HeaderText="Submit Date" ReadOnly="True" SortExpression="Expr1" />
</Columns>
<FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
<PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
<RowStyle BackColor="#DEDFDE" ForeColor="Black" />
<SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#594B9C" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#33276A" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:IHDConnectionString %>"
SelectCommand="SELECT issue.issue_id, issue.pro_id, project.name, issue.type, issue.summary, issue.mem_id, issue.priority, issue.status, issue.impact, CONVERT (date, GETDATE()) AS Expr1 FROM issue INNER JOIN project ON issue.pro_id = project.pro_id"
UpdateCommand="UPDATE [issue] SET [mem_id] = #mem_id, [priority] = #priority, [status] = #status WHERE [issue_id] = #issue_id AND [pro_id] = #pro_id"
<UpdateParameters>
<asp:Parameter Name="mem_id" Type="String" />
<asp:Parameter Name="priority" Type="String" />
<asp:Parameter Name="status" Type="String" />
<asp:Parameter Name="issue_id" Type="Int32" />
<asp:Parameter Name="pro_id" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
here is my redirect page control
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
Response.Redirect("~/redirect.aspx?view=" + e.CommandArgument);
}
Now problem is when I click edit it redirect me to another while it is suppose to edit the record in same page.
Change your Row_Command to this
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if(e.CommandName.ToString() == "view")
{
Response.Redirect("~/redirect.aspx?view=" + e.CommandArgument);
}
}
I would recommend using a link when you need a link, you don't need to do postback to "redirect" the user:
<asp:TemplateField HeaderText="Key#" InsertVisible="False" SortExpression="issue_id">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("issue_id") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<a href='redirect.aspx?view=<%# Eval("issue_id") %>'><%# Eval("issue_id") %></a>
</ItemTemplate>
</asp:TemplateField>
Related
My problem is the next:
I have to make a page which must contain test questions.
I already made it for normal questions, but in the next point, i need a dropdown list in the footer template where the user can choose images names from this list and the textbox get the file path.
The files path is the following:
"~/Dokuments/" + v_tren_dirnev(different folder for every test) + "/Teszt/"
The code for aspx:
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Kerdesek_Valaszok.aspx.cs" Inherits="Kerdesek_Valaszok" %>
<%# Register Src="UserControl/AutoRedirect.ascx" TagName="AutoRedirect" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2"
runat="Server">
<uc1:AutoRedirect ID="AutoRedirect1" runat="server" />
<asp:SqlDataSource ID="SqlDSTreningek" runat="server" ConnectionString="<%$ ConnectionStrings:dbcs %>"SelectCommand="SELECT * FROM [trening] WHERE ([tren_deleted] = #tren_deleted)">
<SelectParameters>
<asp:Parameter DefaultValue="false" Name="tren_deleted" Type="Boolean" />
</SelectParameters>
</asp:SqlDataSource>
<asp:ObjectDataSource ID="odsKerdesek" runat="server" DeleteMethod="DeleteKerdes" InsertMethod="InsertKerdes" SelectMethod="GetAllKerdes" TypeName="trening.KerdesekDataAccessLayer" UpdateMethod="UpdateKerdes">
<SelectParameters>
<asp:Parameter Name="TrenId" Type="Int32" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="KerdId" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="KerdTrenId" Type="Int32" />
<asp:Parameter Name="KerdKerdes" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="KerdId" Type="Int32" />
<asp:Parameter Name="KerdKerdes" Type="String" />
</UpdateParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="odsValaszok" runat="server" DeleteMethod="DeleteValasz" InsertMethod="InsertValasz" SelectMethod="GetAllValasz" TypeName="trening.ValaszokDataAccessLayer" UpdateMethod="UpdateValasz">
<SelectParameters>
<asp:Parameter Name="KerdId" Type="Int32" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="ValaId" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="ValaKerdId" Type="Int32" />
<asp:Parameter Name="ValaValasz" Type="String" />
<asp:Parameter Name="ValaHelyes" Type="Boolean" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="ValaId" Type="Int32" />
<asp:Parameter Name="ValaValasz" Type="String" />
<asp:Parameter Name="ValaHelyes" Type="Boolean" />
</UpdateParameters>
</asp:ObjectDataSource>
<br />
<table id="kerdesek_valaszok">
<tr>
<td colspan="3">
<h2>Tréning kérdések és válaszok karbantartása</h2>
</td>
</tr>
<tr>
<td colspan="3">
<asp:DropDownList ID="ddlTreningek" runat="server" DataSourceID="SqlDSTreningek" DataTextField="tren_megnevezes" DataValueField="tren_id" Font-Size="Large" AutoPostBack="True" OnDataBound="ddlTreningek_DataBound" OnSelectedIndexChanged="ddlTreningek_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
<tr>
<td colspan="3">
<asp:GridView ID="gvKerdesek" runat="server" AutoGenerateColumns="False" DataKeyNames="kerd_id" DataSourceID="odsKerdesek" CellPadding="4" ShowFooter="True" ForeColor="#333333" GridLines="None" HorizontalAlign="Center" OnRowCommand="gvKerdesek_RowCommand" OnSelectedIndexChanged="gvKerdesek_SelectedIndexChanged">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField HeaderText="kerd_id" InsertVisible="False" SortExpression="kerd_id" Visible="False">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("kerd_id") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("kerd_id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="kerd_tren_id" InsertVisible="False" SortExpression="kerd_tren_id" Visible="False">
<EditItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("kerd_tren_id") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("kerd_tren_id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Kérdések" SortExpression="kerd_kerdes">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("kerd_kerdes") %>' MaxLength="250" Size="100"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvTextBox1" runat="server" ErrorMessage="Kötelező a kérdést megadni!" ValidationGroup="update" ControlToValidate="TextBox1" Text="*" ForeColor="Red"></asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("kerd_kerdes") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txbNewKerdes" runat="server" MaxLength="250" Size="100"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvTextBox2" runat="server" ErrorMessage="Kötelező az új kérdést megadni" ValidationGroup="insert" ControlToValidate="txbNewKerdes" Text="*" ForeColor="Red"></asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:ImageButton ID="btnUpdateKerdes" runat="server" CausesValidation="True" ValidationGroup="update" CommandName="UpdateKerdes" CommandArgument='<%# Eval("kerd_id") %>' ImageUrl="~/App_Themes/Theme1/update.png" Height="25" ToolTip="Módosítás" />
<asp:ImageButton ID="btnCancelKerdes" runat="server" CausesValidation="false" CommandName="Cancel" ImageUrl="~/App_Themes/Theme1/cancel.png" Height="25" ToolTip="Mégsem" />
</EditItemTemplate>
<ItemTemplate>
<asp:ImageButton ID="btnEditKerdes" runat="server" CausesValidation="false" CommandName="EditKerdes" CommandArgument='<%# Eval("kerd_id") %>' ImageUrl="~/App_Themes/Theme1/edit.png" Height="25" ToolTip="Szerkesztés" />
<asp:ImageButton ID="btnSelectKerdes" runat="server" CausesValidation="false" CommandName="SelectKerdes" CommandArgument='<%# Eval("kerd_id") %>' ImageUrl="~/App_Themes/Theme1/select.png" Height="25" ToolTip="Kiválasztás" />
<asp:ImageButton ID="btnDeleteKerdes" runat="server" CausesValidation="false" CommandName="DeleteKerdes" CommandArgument='<%# Eval("kerd_id") %>' ImageUrl="~/App_Themes/Theme1/delete.png" Height="25" ToolTip="Törlés" OnClientClick="return confirm('Biztosan törölni akarja ezt a kérdést és a hozzátartozó válaszokat?');" />
</ItemTemplate>
<FooterTemplate>
<asp:ImageButton ID="btnInsertKerdes" CausesValidation="true" ValidationGroup="insert" runat="server" OnClick="btnInsertKerdes_Click" ImageUrl="~/App_Themes/Theme1/insert.png" Height="25" ToolTip="Új kérdés rögzítése" />
<!--AG dropdown list -->
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList>
</FooterTemplate>
<ItemStyle Wrap="False" />
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FF9900" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
<br />
<asp:ValidationSummary ID="ValidationSummary1" ValidationGroup="insert" runat="server" ForeColor="Red" ShowMessageBox="true" ShowSummary="false" />
<asp:ValidationSummary ID="ValidationSummary2" ValidationGroup="update" runat="server" ForeColor="Red" ShowMessageBox="true" ShowSummary="false" />
<asp:ValidationSummary ID="ValidationSummary3" ValidationGroup="insertValasz" runat="server" ForeColor="Red" ShowMessageBox="true" ShowSummary="false" />
<asp:ValidationSummary ID="ValidationSummary4" ValidationGroup="updateValasz" runat="server" ForeColor="Red" ShowMessageBox="true" ShowSummary="false" />
</td>
</tr>
<tr>
<td colspan="3">
<br />
<asp:GridView ID="gvValaszok" runat="server" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="vala_id" DataSourceID="odsValaszok" ShowFooter="True" ForeColor="#333333" GridLines="None" EmptyDataText="Nincsenek még válaszok megadva!" HorizontalAlign="Center" OnRowCommand="gvValaszok_RowCommand">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField HeaderText="vala_id" InsertVisible="False" SortExpression="vala_id" Visible="False">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("vala_id") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("vala_id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="vala_kerd_id" SortExpression="vala_kerd_id" Visible="False">
<EditItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("vala_kerd_id") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("vala_kerd_id") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblNewValaKerdId" runat="server" Text='<%# Bind("vala_kerd_id") %>'></asp:Label>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Válaszok" SortExpression="vala_valasz">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("vala_valasz") %>' MaxLength="250" size="100"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("vala_valasz") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txbNewValasz" runat="server" MaxLength="250" size="100"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvTextBox3" runat="server" ErrorMessage="Kötelező az új választ megadni" ValidationGroup="insertValasz" ControlToValidate="txbNewValasz" Text="*" ForeColor="Red"></asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Helyes-e?" SortExpression="vala_helyes">
<EditItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("vala_helyes") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("vala_helyes") %>' Enabled="false" />
</ItemTemplate>
<FooterTemplate>
<asp:CheckBox ID="cbxNewHelyes" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:ImageButton ID="btnUpdateValasz" runat="server" CausesValidation="True" CommandName="UpdateValasz" CommandArgument='<%# Eval("vala_id") %>' ImageUrl="~/App_Themes/Theme1/update.png" Height="25" ToolTip="Módosítás" />
<asp:ImageButton ID="btnCancelValasz" runat="server" CausesValidation="false" CommandName="Cancel" ImageUrl="~/App_Themes/Theme1/cancel.png" Height="25" ToolTip="Mégsem" />
</EditItemTemplate>
<ItemTemplate>
<asp:ImageButton ID="btnEditValasz" runat="server" CausesValidation="false" CommandName="Edit" ImageUrl="~/App_Themes/Theme1/edit.png" Height="25" ToolTip="Szerkesztés" />
<asp:ImageButton ID="btnDeleteValasz" runat="server" CausesValidation="false" CommandName="DeleteValasz" CommandArgument='<%# Eval("vala_id") %>' ImageUrl="~/App_Themes/Theme1/delete.png" Height="25" ToolTip="Törlés" OnClientClick="return confirm('Biztosan törölni akarja ezt a választ?');" />
</ItemTemplate>
<FooterTemplate>
<asp:ImageButton ID="btnInsertValasz" CausesValidation="true" ValidationGroup="insertValasz" runat="server" OnClick="btnInsertValasz_Click" ImageUrl="~/App_Themes/Theme1/insert.png" Height="25" ToolTip="Új kérdés rögzítése" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
</td>
</tr>
</table>
The code behind this:
public partial class Kerdesek_Valaszok : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnInsertKerdes_Click(object sender, EventArgs e)
{
odsKerdesek.InsertParameters["KerdTrenId"].DefaultValue = ddlTreningek.SelectedValue;
odsKerdesek.InsertParameters["KerdKerdes"].DefaultValue = ((TextBox)gvKerdesek.FooterRow.FindControl("txbNewKerdes")).Text;
odsKerdesek.Insert();
gvKerdesek.DataBind();
}
protected void btnInsertValasz_Click(object sender, EventArgs e)
{
if (gvKerdesek.SelectedRow != null)
{
odsValaszok.InsertParameters["ValaKerdId"].DefaultValue = ((Label)gvValaszok.Rows[0].FindControl("Label3")).Text;
odsValaszok.InsertParameters["ValaValasz"].DefaultValue = ((TextBox)gvValaszok.FooterRow.FindControl("txbNewValasz")).Text;
odsValaszok.InsertParameters["ValaHelyes"].DefaultValue = ((CheckBox)gvValaszok.FooterRow.FindControl("cbxNewHelyes")).Checked.ToString();
odsValaszok.Insert();
gvValaszok.DataBind();
} else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert('Nincs a kérdés kiválasztva!');", true);
}
}
protected void ddlTreningek_DataBound(object sender, EventArgs e)
{
odsKerdesek.SelectParameters["TrenId"].DefaultValue = ddlTreningek.SelectedValue;
odsKerdesek.Select();
}
protected void ddlTreningek_SelectedIndexChanged(object sender, EventArgs e)
{
odsKerdesek.SelectParameters["TrenId"].DefaultValue = ddlTreningek.SelectedValue;
odsKerdesek.Select();
gvKerdesek.SelectRow(-1);
}
protected void gvKerdesek_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "SelectKerdes")
{
string tmp = e.CommandArgument.ToString();
int selind = ((GridViewRow)((ImageButton)e.CommandSource).NamingContainer).RowIndex;
odsValaszok.SelectParameters["KerdId"].DefaultValue = e.CommandArgument.ToString();
odsValaszok.Select();
gvKerdesek.SelectedIndex = selind;
gvKerdesek.DataBind();
} else if (e.CommandName == "DeleteKerdes")
{
KerdesekDataAccessLayer.DeleteKerdes(Convert.ToInt32(e.CommandArgument));
gvKerdesek.DataBind();
} else if (e.CommandName == "EditKerdes")
{
int rowindex = ((GridViewRow)((ImageButton)e.CommandSource).NamingContainer).RowIndex;
gvKerdesek.EditIndex = rowindex;
gvKerdesek.DataBind();
} else if (e.CommandName == "UpdateKerdes")
{
int rowindex = ((GridViewRow)((ImageButton)e.CommandSource).NamingContainer).RowIndex;
int kerd_id = Convert.ToInt32(e.CommandArgument);
odsKerdesek.UpdateParameters["KerdId"].DefaultValue = ((Label)gvKerdesek.Rows[rowindex].FindControl("Label1")).Text;
odsKerdesek.UpdateParameters["KerdKerdes"].DefaultValue = ((TextBox)gvKerdesek.Rows[rowindex].FindControl("TextBox1")).Text;
odsKerdesek.Update();
gvKerdesek.EditIndex = -1;
gvKerdesek.DataBind();
}
}
protected void gvValaszok_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "DeleteValasz")
{
ValaszokDataAccessLayer.DeleteValasz(Convert.ToInt32(e.CommandArgument));
gvValaszok.DataBind();
} else if (e.CommandName == "UpdateValasz")
{
int rowindex = ((GridViewRow)((ImageButton)e.CommandSource).NamingContainer).RowIndex;
int vala_id = Convert.ToInt32(e.CommandArgument);
odsValaszok.UpdateParameters["ValaId"].DefaultValue = ((Label)gvValaszok.Rows[rowindex].FindControl("Label1")).Text;
odsValaszok.UpdateParameters["ValaValasz"].DefaultValue = ((TextBox)gvValaszok.Rows[rowindex].FindControl("TextBox1")).Text;
odsValaszok.UpdateParameters["ValaHelyes"].DefaultValue = ((CheckBox)gvValaszok.Rows[rowindex].FindControl("CheckBox1")).Checked.ToString();
odsValaszok.Update();
gvValaszok.EditIndex = -1;
gvValaszok.DataBind();
}
}
}
As i told before, the problem is the following. Here is an image for the look and for the asp code. I made an alternative solution, but i really want this too.
The image
I need a code for this:
The dropdown list must contain a folder file names, and after i choose one of them, the text box on the left get filled with the path for the file like this:
~/Dokuments/10001/Teszt/Slide01.JPG
The 10001 can be changed by the top dropdown list, which contains the different test names. If you select a test, then the path changes automatically, so it is not a problem.
And then you can't change the textbox's content only one way, when you choose the default element from the dropdown list.
I have a nested gridview inside another gridview. The parent gridview has a list of tasks, and each task has a list of steps (the child gridview). Each step has a checkbox so once a user is done with a step, he'll check the checkbox and that will fire the CheckChanged event in which I have a stored procedure to update the database so the checked step registers as completed.
I have a CheckChanged event that looks for the step ID of the row the checked checkbox was in, then fires off the stored procedure using the step ID as an input parameter. This works. However, steps can be added, and for some reason, when a check box on an earlier step is clicked, the code that looks for the step ID won't go backwards and recognize the step ID. In other words, if a if the the step ID of a certain task is 20, and it is checked and the event fires off, if I add a step to an earlier task (a task listed higher on the gridview) and that step has an ID of 21, clicking on it will constantly register the step ID as 20, as if the CheckChanged event doesn't recognize a step added to another task. Here is my code:
aspx:
<asp:GridView ID="GridView1"
DataKeyNames="TaskID"
runat="server"
OnRowDataBound="GridView1_OnRowDataBound"
CssClass="DefaultGrid"
onRowCommand="GridView1_RowCommand"
EmptyDataText = "<br/>There are no Tasks in this Project."
AllowPaging="True"
AllowSorting="True"
CellPadding="4"
DataSourceID="SqlDataSource_mp_Display_Tasks_Home"
ForeColor="#333333"
GridLines="None"
AutoGenerateColumns="False">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<RowStyle CssClass=" table-responsive body-content " />
<Columns>
<asp:CommandField ShowSelectButton="False" />
<asp:TemplateField>
<ItemTemplate>
<img alt = "" style="cursor: pointer" src="Images/plus.png" />
<asp:Panel ID="pnlOrders" runat="server" Style="display:none">
<asp:GridView ID="GridView2"
runat="server"
onRowCommand="GridView2_RowCommand"
Datakeynames="TaskStepID"
CssClass="ChildGrid"
EmptyDataText="<br/>There are no Steps in this Task."
AutoGenerateColumns="false"
onselectedindexchanged="GridView2_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="TaskStepID" HeaderText="TaskStepID" Visible="true" />
<asp:BoundField DataField="TaskID" HeaderText="TaskID" Visible="false" />
<asp:BoundField DataField="TaskStepTypeID" HeaderText="TaskStepTypeID" Visible="false"/>
<asp:BoundField DataField="TaskStepPriority" HeaderText="Task Step Priority" Visible="false" />
<asp:BoundField ItemStyle-Width="70%" DataField="TaskStepDesc" HeaderText="Step Description" />
<asp:TemplateField HeaderText="Step Completed" ItemStyle-Width="15%" >
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Checkbox ID="TaskStepCompleted"
OnCheckedChanged="TaskStepCompleted_CheckedChanged"
Checked='<%# Eval("TaskStepCompleted") %>'
runat="server"
AutoPostBack="true" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TaskStepComment" HeaderText="TaskStepComment" Visible="false" />
<asp:TemplateField HeaderText="Step Activity" ItemStyle-Width="15%">
<ItemTemplate>
<asp:LinkButton Text="Add" ID="Addstep" runat="server" CommandName="addstep" CommandArgument='<%# Eval("TaskStepID") %>'/>
<asp:LinkButton Text="Edit" ID="Editstep" runat="server" CommandName="editstep" CommandArgument='<%# Eval("TaskStepID") %>'/>
<asp:LinkButton Text="Delete" ID="Deletestep" runat="server" CommandName="deletestep" OnClientClick="return confirm('<%=AlertMe%>');" CommandArgument='<%# Eval("TaskStepID") %>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TaskID" HeaderText="Task ID" Visible="false"/>
<asp:BoundField DataField="ProjectID" HeaderText="Project ID" Visible="false" />
<asp:BoundField DataField="TaskTypeID" HeaderText="Task Type ID" Visible="false" />
<asp:BoundField DataField="TaskCompleted" HeaderText="Taske Completed?" Visible="false" />
<asp:BoundField DataField="TaskCreationDate" HeaderText="Task Creation Date" Visible="false" />
<asp:BoundField DataField="TaskSubmitterID" HeaderText="Task Submitter ID" Visible="false" />
<asp:BoundField DataField="DepartmentID" HeaderText="DepartmentID" Visible="false" />
<asp:BoundField DataField="TaskDueDateCommentType" HeaderText="Due Date Comment" Visible="false" />
<asp:BoundField DataField="TaskLastUpdatedDate" HeaderText="Task Last Updated Date" Visible="false" />
<asp:BoundField DataField="TaskLastUpdatedUserID" HeaderText="Task Last Updated UserID" Visible="false" />
<asp:BoundField DataField ="TaskSubmitterName" HeaderText="Task Submitter Name" Visible="false" />
<asp:BoundField DataField="TaskLastUpdatedUser" HeaderText="Task Last Updated User" Visible="false" />
<asp:BoundField DataField="DepartmentDesc" HeaderText="Dept" visible="false"/>
<asp:TemplateField HeaderText="Task Description">
<ItemTemplate>
<asp:Label ID="TaskDescription" runat="server" Text='<%# HighlightText(Eval("TaskDescription").ToString()) %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="40%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="% Comp.">
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="PercentCompleted" runat="server" Text='<%# (String.IsNullOrEmpty(Eval("PercentCompleted").ToString()) ? "0" : Eval("PercentCompleted")) + " %" %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TaskDueDate" HeaderStyle-HorizontalAlign="Right" HeaderText="Task Due Date" DataFormatString="{0:MM-dd-yyyy}" visible="true"/>
<asp:BoundField DataField="TaskTypeName" HeaderText="Task Type" visible="true" />
<asp:BoundField DataField="DepartmentAbbrev" HeaderText="Dept" Visible="true" />
<asp:TemplateField HeaderText="Activity">
<ItemTemplate>
<asp:LinkButton Text="Edit" ID="Edittask" runat="server" CommandName="edittask" CommandArgument='<%# Eval("TaskID") %>'/>
<asp:LinkButton Text="Delete" ID="Deletetask" runat="server" CommandName="deletetask" OnClientClick="return confirm('Are you sure you wish to Delete this Task?');" CommandArgument='<%# Eval("TaskID") %>'/>
<asp:LinkButton Text="Comments" ID="Detailstask" runat="server" CommandName="detailstask" CommandArgument='<%# Eval("TaskID") %>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource_mp_Display_Tasks_Home" runat="server" FilterExpression="TaskDescription LIKE '%{0}%'" ConnectionString="<%$ ConnectionStrings:IntelliBaseConnectionString_mp_Display_Projects_Home %>" SelectCommand="mp_Display_Tasks_Home" SelectCommandType="StoredProcedure" ProviderName="System.Data.SqlClient">
<SelectParameters>
<asp:Parameter Name="Incoming_ProjectID" Type="Int32" />
</SelectParameters>
<FilterParameters>
<asp:ControlParameter Name="TaskDescription" ControlID="txtSearchtasks" PropertyName="Text"/>
</FilterParameters>
</asp:SqlDataSource>
cs:
protected void TaskStepCompleted_CheckedChanged(object sender, EventArgs e)
{
// this nested foreach grabs the taskstepID number for the row in which the checkbox was just checked.
foreach (GridViewRow row in GridView1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
GridView GridView2 = (GridView)row.FindControl("GridView2");
if (GridView2 != null)
{
foreach (GridViewRow Row in GridView2.Rows)
{
if (Row.RowType == DataControlRowType.DataRow)
{
System.Web.UI.WebControls.CheckBox chk = (System.Web.UI.WebControls.CheckBox)Row.FindControl("TaskStepCompleted");
if (chk.Checked || !chk.Checked)
{
Session["TaskStepID"] = GridView2.DataKeys[Row.RowIndex]["TaskStepID"].ToString();
}
}
}
}
}
}
// autopost back the check box to run the stored procedure
var TaskStepID = Session["TaskStepID"].ToString();
var ProjectID = Session["ProjectID"].ToString();
using (var conn = new SqlConnection("Data Source=orlandosql1;Initial Catalog=IntelliBase;Persist Security Info=True;User ID=trainingsurveys_webuser;Password=C#mb3rSQL;"))
using (SqlCommand cmd = new SqlCommand("dbo.mp_Task_Step_Completed_Toggle", conn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("#TaskStepID", SqlDbType.Int).Value = TaskStepID;
cmd.Parameters.Add("#AdminUserID", SqlDbType.Int).Value = "10";
cmd.Parameters.Add("#LogActionItemID", SqlDbType.Int).Value = "15";
cmd.Parameters.AddWithValue("#DTStamp", SqlDbType.DateTime.ToString("d")).Value = DateTime.Now.ToString("d");
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
Response.Redirect("Tasks.aspx?id=" + ProjectID.ToString());
}
}
I tried my best to describe the issue. To recap: nested gridview has rows with check boxes. Clicking the checkbox automatically updates db tables, but regardless of check box row, the CheckedChanged code will only register the ID of the most recent ID. Any insight is appreciated.
Carlos
If I understand correctly, I believe your issue comes with how you think you are grabbing the TaskStepID of your GridViewRow. You are doing a lot of unnecessary work. Instead of iterating every row of both GridViews, just grab the GridViewRow of the CheckBox that was just clicked.
CheckBox cb = (CheckBox)sender;
GridViewRow row = (GridViewRow)cb.NamingContainer;
GridView gv = (GridView)row.NamingContainer;
string taskStepID = gv.DataKeys[row.RowIndex].Value.ToString();
Notice how by iterating each row like you were, you were always getting the TaskStepID of the last row. So when you added a row before it, it was using the last row instead of the one you expected.
I am trying to make my gridview update a SQL record but it is not updating the values.
Here is the aspx code:
<asp:GridView ID="GridView1" runat="server" GridLines="None" AutoGenerateColumns="false"
onrowcancelingedit="GridView1_RowCancelling"
OnRowDeleting ="GridView1_RowDeleting"
onrowediting="GridView1_RowEditing"
onrowupdating="GridView1_RowUpdating"
DataKeyNames="RID"
CssClass="mGrid"
PagerStyle-CssClass="pgr"
AlternatingRowStyle-CssClass="alt">
<Columns>
<asp:TemplateField Visible="false" HeaderText="RID">
<ItemTemplate>
<asp:Label runat="server" ID="RID" Text='<%#Bind("RID")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Short Description">
<ItemTemplate>
<asp:Label runat="server" ID="short_lbl" Text='<%#Bind("SHORT_DESCRIPTION") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="SHORT_DESCRIPTION" Text='<%#Bind("SHORT_DESCRIPTION") %>' />
<asp:RequiredFieldValidator runat="server" ID="valShort" ControlToValidate="SHORT_DESCRIPTION" ValidationGroup="var1" ErrorMessage="*" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<asp:Label runat="server" ID="desc_label" Text='<%#Bind("DESCRIPTION") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="DESCRIPTION" Text='<%#Bind("DESCRIPTION") %>' />
<asp:RequiredFieldValidator runat="server" ID="valLast" ControlToValidate="DESCRIPTION" ValidationGroup="var1" ErrorMessage="*" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Action">
<ItemTemplate>
<asp:LinkButton ID="btnEdit" Text="Edit" runat="server" CommandName="Edit" />
<br />
<asp:LinkButton ID="btnDelete" Text="Delete" runat="server" CommandName="Delete" />
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="btnUpdate" Text="Update" runat="server" CommandName="Update" />
<asp:LinkButton ID="btnCancel" Text="Cancel" runat="server" CommandName="Cancel" />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
And the update function itself.
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string s = GridView1.DataKeys[e.RowIndex].Value.ToString();
Label RID = GridView1.Rows[e.RowIndex].FindControl("RID") as Label;
TextBox SHORT_DESCRIPTION = GridView1.Rows[e.RowIndex].FindControl("SHORT_DESCRIPTION") as TextBox;
TextBox DESCRIPTION = GridView1.Rows[e.RowIndex].FindControl("DESCRIPTION") as TextBox;
String UpdateQuery = string.Format("UPDATE TAXONOMIES SET SHORT_DESCRIPTION='{0}', DESCRIPTION='{1}' WHERE RID = {2}", SHORT_DESCRIPTION.Text, DESCRIPTION.Text, Convert.ToInt32(RID.Text));
GridView1.EditIndex = -1;
BindGridData(UpdateQuery);
}
If I put a breakpoint and look at the value, I can see that is is not the newly typed in value. I'm not sure what is going on.
I think the problem is you are binding you grid on the page-load event.
try binding it in if (!IsPostBack)
Example
private void Page_Load()
{
if (!IsPostBack)
{
//bind your grid here.
}
}
use this code
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="id" DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="id" HeaderText="id" ReadOnly="True"
SortExpression="id" />
<asp:BoundField DataField="regGroupID" HeaderText="regGroupID"
SortExpression="regGroupID" />
<asp:BoundField DataField="amountReceived" HeaderText="amountReceived"
SortExpression="amountReceived" />
<asp:BoundField DataField="other" HeaderText="other" SortExpression="other" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [Table]"
UpdateCommand="UPDATE [Table] SET [regGroupID] = #regGroupID, [amountReceived] = #amountReceived, [other] = #other WHERE [id] = #id">
<DeleteParameters>
<asp:Parameter Name="id" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="regGroupID" Type="Int32" />
<asp:Parameter Name="amountReceived" Type="Decimal" />
<asp:Parameter Name="other" Type="String" />
<asp:Parameter Name="id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
here I set id as the primary key
table structure is
Try changing the Eval to Bind. Eval is read-only so you can't actually update the value.
Error Message:
The variable name '#Bitnet' has already been declared. Variable names must be unique within a query batch or stored procedure. When trying to edit gridview.
I want to be able to update the checkbox field. This gridview is based on a table join.
<asp:Content ID="Content4" runat="server" contentplaceholderid="ContentPlaceHolder2">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="INST_ID,BITNET" DataSourceID="SqlDataSource1" AllowPaging="True" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="INST_ID" HeaderText="INST_ID" ReadOnly="True" SortExpression="INST_ID" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
<asp:BoundField DataField="Prefix" HeaderText="Prefix" SortExpression="Prefix" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="Address1" HeaderText="Address1" SortExpression="Address1" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="State" HeaderText="State" SortExpression="State" />
<asp:BoundField DataField="Zip" HeaderText="Zip" SortExpression="Zip" />
<asp:BoundField DataField="Country" HeaderText="Country" SortExpression="Country" />
<asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
<asp:BoundField DataField="Fax" HeaderText="Fax" SortExpression="Fax" />
<asp:BoundField DataField="BITNET" HeaderText="BITNET" ReadOnly="True" SortExpression="BITNET" />
<asp:TemplateField HeaderText="Active">
<ItemTemplate>
<asp:CheckBox ID="Active" runat="server" Checked='<%# Eval("Active").ToString() == "1" ? true:false %>' Enabled="false" />
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox ID="Active" runat="server" Checked="true" Enabled="false" />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ASPLOGINConnectionString %>" SelectCommand="SELECT IALO.INST_ID, IALO.FirstName, IALO.LastName, IALO.Prefix, IALO.Title, IALO.Address1, IALO.City, IALO.State, IALO.Zip, IALO.Country, IALO.Phone, IALO.Fax, IALO.BITNET, IALO.Active FROM CEOTable INNER JOIN IALO ON CEOTable.Inst_ID = IALO.INST_ID WHERE (CEOTable.Bitnet = #Bitnet)">
</asp:SqlDataSource>
You have to declare the parameter first. Then only you can use that. It should be something like this
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ASPLOGINConnectionString %>" SelectCommand="SELECT IALO.INST_ID, IALO.FirstName, IALO.LastName, IALO.Prefix, IALO.Title, IALO.Address1, IALO.City, IALO.State, IALO.Zip, IALO.Country, IALO.Phone, IALO.Fax, IALO.BITNET, IALO.Active FROM CEOTable INNER JOIN IALO ON CEOTable.Inst_ID = IALO.INST_ID WHERE (CEOTable.Bitnet = #Bitnet)">
<SelectParameters>
<asp:Parameter Name="Bitnet" Type="Int32" DefaultValue="0" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Bitnet" Type="Int32" DefaultValue="0" />
</UpdateParameters>
</asp:SqlDataSource>
I solved my own question issue was that I was not clearing my parameters first
protected void Page_Load(object sender, EventArgs e)
{
SqlDataSource1.SelectParameters.Clear();
}
That fixed the issue it works fine now.
i have a problem i am binding data in grid view from datasource and there i am geting information of different type of order status start form 1 to 7 . i do not want to display the status 7 data in my grid view . can you help me how we
<data:EntityGridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
DataSourceID="ActiveOrdersDataSource" Width="100%" DataKeyNames="OrderNo" AllowMultiColumnSorting="false"
OnRowCommand="GridView1_RowCommond" OnRowDataBound="GridView1_OnRowDataBound"
DefaultSortDirection="Descending" ExcelExportFileName="Export_ActiveOrders.xls">
<Columns>
<asp:CommandField ShowSelectButton="True" SelectText="Edit" />
<asp:BoundField DataField="OrderNo" ItemStyle-HorizontalAlign="Center" HeaderText="Order No" SortExpression="[OrderNo]" />
<asp:BoundField DataField="OrderDate" DataFormatString="{0:d}" HtmlEncode="False"
HeaderText="Order Date" SortExpression="[OrderDate]" />
<asp:BoundField DataField="PickupCompanyName" HeaderText="Pickup Company" SortExpression="[PickupCompanyName]" Visible="false" />
<asp:BoundField DataField="DeliveryCompanyName" HeaderText="Delivery Company" SortExpression="[DeliveryCompanyName]" Visible="false" />
<data:HyperLinkField HeaderText="Ac.No." ControlStyle-ForeColor="Black" DataContainer="AccountNumberSource"
DataTextField="AccountNumber" />
<data:HyperLinkField HeaderText="Client" DataContainer="AccountNumberSource"
DataTextField="Name" />
<asp:BoundField DataField="Caller" ItemStyle-HorizontalAlign="Center" HeaderText="Caller" SortExpression="[Caller]" />
<asp:BoundField DataField="Department" ItemStyle-HorizontalAlign="Center" HeaderText="Department" SortExpression="[Department]" />
<asp:BoundField DataField="Reference" HeaderText="Reference" SortExpression="[Reference]" />
<asp:TemplateField HeaderText="Driver" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="lblDriver" runat="server" Text='<%#Eval("CurrentDriverNumberSource.Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<data:HyperLinkField HeaderText="Service" ControlStyle-ForeColor="Black" DataContainer="ServiceTypeIdSource"
DataTextField="Description" />
<data:HyperLinkField HeaderText="Vehicle" ControlStyle-ForeColor="Black" DataContainer="VehicleTypeIdSource"
DataTextField="Description" />
<asp:TemplateField HeaderText="Status" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="lblStatus" runat="server" Text='<%#Eval("StatusID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="TotalAmount" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblAmount" runat="server" Text='<%# Eval("TotalAmount","{0:C2}")%>' ></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Right" />
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<b>No Active Orders Found!</b>
</EmptyDataTemplate>
</data:EntityGridView>
and for datasource i use this
<data:ActiveOrdersDataSource ID="ActiveOrdersDataSourcebyCompany" runat="server" SelectMethod="GetPaged" EnablePaging="True" EnableSorting="True" EnableDeepLoad="True">
<DeepLoadProperties Method="IncludeChildren" Recursive="False">
<Types>
<data:ActiveOrdersProperty Name="Clients" />
<data:ActiveOrdersProperty Name="Companies" />
<data:ActiveOrdersProperty Name="Drivers" />
<data:ActiveOrdersProperty Name="SalesPeople" />
<data:ActiveOrdersProperty Name="ServiceTypes" />
<data:ActiveOrdersProperty Name="VehicleTypes" />
<data:ActiveOrdersProperty Name="Zones" />
</Types>
</DeepLoadProperties>
<Parameters>
<asp:SessionParameter Name="CompanyId" SessionField="CompanyId" Type="String" />
<data:SqlParameter Name="WhereClause" UseParameterizedFilters ="false">
<Filters>
<%--<data:CustomParameter Name="WhereClause" Value="" ConvertEmptyStringToNull="false" />
<data:CustomParameter Name="OrderByClause" Value="" ConvertEmptyStringToNull="false" />
<asp:ControlParameter Name="PageIndex" ControlID="GridView1" PropertyName="PageIndex"
Type="Int32" />
<asp:ControlParameter Name="PageSize" ControlID="GridView1" PropertyName="PageSize"
Type="Int32" />
<data:CustomParameter Name="RecordCount" Value="0" Type="Int32" />--%>
</Parameters>
</data:ActiveOrdersDataSource>
Goutam,
you can use the Filter Tag to set the value you want like:
<Parameters>
<data:SqlParameter Name="WhereClause" UseParameterizedFilters="false">
<Filters>
<data:ChartOfAccountsFilter Column="Status" ComparisionType="NotContains" DefaultValue="7" />
</Filters>
</data:SqlParameter>
</Parameters>
you can make as per this code:
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim x As String
x = e.Row.Cells(1).Text
Dim y As String
y = e.Row.Cells(8).Text
If Convert.ToInt32(x) <= Convert.ToInt32(y) Then
e.Row.ForeColor = System.Drawing.Color.Blue
End If
End If
End Sub