I have a gridView which works nicely until I open a new window by clicking a button. When the new window is opened the values in one of the columns 'lblTotalPrice' gets erased. 'lblTotalPrice' is a template field, which is calculated in MealList_RowDataBound (quantity * price). The footer for the column, however is not affected when the new window is opened (also gets its value in MealList_RowDataBound).
Also the font-size of the data-bound columns are changed when the new window is opened.
Any ideas of what might cause this? When stepping through the code there are no other lines executed after btnEnvComment_Click
When gridView is databound again, everything is back to normal.
The gridView:
<rwg:BulkEditGridView ID="MealList" runat="server" AutoGenerateColumns="False" ShowFooter="True" GridLines="Vertical" CellPadding="4"
BackColor="White" DataKeyNames="ItemId,ProductId" SaveButtonID="SaveButton"
DataSourceID="SqlMealItems" style="float:left"
OnRowDataBound="MealList_RowDataBound" OnRowCreated="MealList_RowCreated" CssClass="gridView">
<AlternatingRowStyle CssClass="MealListItemAlt" BackColor="#a6dbed" />
<Columns>
<asp:BoundField DataField="ProductId" HeaderText="Prod #" HeaderStyle-Wrap="false" ReadOnly="True" >
<HeaderStyle Wrap="False" Width="60px"></HeaderStyle>
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
<asp:BoundField DataField="ProductName" HeaderText="Namn" ReadOnly="True" ItemStyle-Wrap="False" >
<ItemStyle Width="150px" />
</asp:BoundField>
<asp:BoundField DataField="Quantity" HeaderText="Antal" ControlStyle-CssClass="numeric" >
<ControlStyle CssClass="numeric" Width="30px"></ControlStyle>
</asp:BoundField>
<asp:TemplateField HeaderText="Enhet">
<ItemTemplate>
<asp:DropDownList ID="DropDownUnit" OnSelectedIndexChanged="DropDownUnit_SelectedIndexChanged"
AutoPostBack="False" runat="server" DataTextField="Unit" DataValueField="Unit">
</asp:DropDownList>
</ItemTemplate>
<ControlStyle Width="70px" />
</asp:TemplateField>
<asp:BoundField HeaderText="á pris" ReadOnly="True" ControlStyle-CssClass="rightAlign" ItemStyle-Wrap="False">
<ControlStyle CssClass="numeric" ></ControlStyle>
<ItemStyle HorizontalAlign="Right" Width="80px" />
</asp:BoundField>
<asp:TemplateField HeaderText="Totalt" ItemStyle-Wrap="False">
<ItemTemplate>
<asp:label ID="lblTotalPrice" runat = server></asp:label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Right" Width="80px" />
<FooterTemplate>
<asp:Label ID="lblTotalPricePerMeal" runat="server"></asp:Label>
</FooterTemplate>
<FooterStyle HorizontalAlign="Right" Font-Bold="true" Font-Overline="True" Wrap="False" />
</asp:TemplateField>
<asp:BoundField DataField="Unit" HeaderText="h" ReadOnly="True" />
<asp:TemplateField>
<ItemTemplate>
<asp:image runat="server" ID="imgBlob" Width="24"></asp:image>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label runat="server" ID="lblError"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle CssClass="MealListFooter" />
<HeaderStyle CssClass="MealListHead" />
</rwg:BulkEditGridView>
The code for the button that open the new window:
protected void btnEnvComment_Click(object sender, EventArgs e)
{
int offsetPos = 125; // set placement of new window
String URL = "EnvComment.aspx?MealID=" + Session["MealId"];
String responsCommand = "window.open('" + URL + "','_blank','height=400,width=300,top=" + ",left=" + offsetPos.ToString() + offsetPos.ToString() + ",titlebar=1')";
Response.Write("<script>");
Response.Write(responsCommand);
Response.Write("</script>");
}
Related
I'm having a GridView to display few columns. when I click the edit button in the GridView, it displays a DropDownList for one column which has a list of values to select.
I need to select a value and click on the Update button to update the database with the latest selected value.
<asp:GridView ID="GrdAttributesView" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" CssClass="well"
EmptyDataText="No Records to display."
OnPageIndexChanging="GrdAttributesView_PageIndexChanging"
OnRowCancelingEdit="GrdAttributesView_RowCancelingEdit"
OnRowEditing="GrdAttributesView_RowEditing"
OnRowUpdated="GrdAttributesView_RowUpdated"
OnRowUpdating="GrdAttributesView_RowUpdating"
OnSelectedIndexChanged="GrdAttributesView_SelectedIndexChanged"
OnSorting="GrdAttributesView_Sorting"
OnRowDeleting="GrdAttributesView_RowDeleting"
OnRowDeleted="GrdAttributesView_RowDeleted"
OnRowDataBound="GrdAttributesView_RowDataBound" PagerSettings-Mode="Numeric"
PagerStyle-Font-Bold="true" PageSize="20" ShowHeaderWhenEmpty="True">
<Columns>
<%-- <asp:TemplateField HeaderText="Globalized Indicator">
<ItemTemplate>
<asp:CheckBox ID="Chk_GlobalizedIndicatorGrid" runat="server" Width="55px" OnCheckedChanged="Chk_GlobalizedIndicatorGrid_CheckedChanged" Text='<%# Eval("GlobalizedInd") %>' Checked ='<%# Eval("GlobalizedInd") == DBNull.Value ? false : Convert.ToBoolean(Eval("GlobalizedInd")) %>' Enabled="false"/>
</ItemTemplate>
</asp:TemplateField>--%>
<asp:CommandField HeaderText="Edit Record" ItemStyle-Width="150px" ShowEditButton="True" ShowHeader="True" ShowDeleteButton="true">
<ItemStyle Width="100px" />
</asp:CommandField>
<asp:BoundField HeaderText="Added Date" DataField="AddedDate" ItemStyle-Width="700px" ReadOnly="true" ControlStyle-Width="700px">
<ControlStyle Width="200px"></ControlStyle>
<ItemStyle Width="200px"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="Created By" DataField="CreatedBy" ItemStyle-Width="700px" ReadOnly="true" ControlStyle-Width="700px">
<ControlStyle Width="100px"></ControlStyle>
<ItemStyle Width="100px"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="Ticket Number" DataField="TicketNumber" ItemStyle-Width="200px" ReadOnly="true" ControlStyle-Width="700px">
<ControlStyle Width="200px"></ControlStyle>
<ItemStyle Width="200px"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="Ticket URL" DataField="TIcketURL" ItemStyle-Width="200px" ReadOnly="true" ControlStyle-Width="700px">
<ControlStyle Width="600px"></ControlStyle>
<ItemStyle Width="600px"></ItemStyle>
</asp:BoundField>
<asp:TemplateField HeaderText="Hours Spent" ItemStyle-Width="100px" ControlStyle-Width="700px">
<ControlStyle Width="100px"></ControlStyle>
<ItemStyle Width="100px"></ItemStyle>
<ItemTemplate>
<asp:Label ID="LblHoursSpent" runat="server" Text='<%# Eval("HoursSpent")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="LblHoursSpent" runat="server" Text='<%# Eval("HoursSpent")%>' Visible="false"></asp:Label>
<asp:DropDownList ID="CmbHoursSpent" runat="server" >
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Minutes Spent" ItemStyle-Width="100px" ControlStyle-Width="700px">
<ControlStyle Width="120px"></ControlStyle>
<ItemStyle Width="120px"></ItemStyle>
<ItemTemplate>
<asp:Label ID="LblMinutesSpent" runat="server" Text='<%# Eval("MinutesSpent")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="LblMinutesSpent" runat="server" Text='<%# Eval("MinutesSpent")%>' Visible="false"></asp:Label>
<%--<asp:DropDownList ID="CmbHoursSpent" AppendDataBoundItems="true" DataTextField="NumberofHoursSpent" DataValueField="HoursSpent" AutoPostBack="false" runat="server" OnSelectedIndexChanged="CmbHoursSpent_SelectedIndexChanged" enabled="true">
</asp:DropDownList>--%>
<asp:DropDownList ID="CmbMinutesSpent" runat="server">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle Font-Bold="True" />
</asp:GridView>
The code behind is as follows:
protected void GrdAttributesView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && GrdAttributesView.EditIndex == e.Row.RowIndex)
{
if ((e.Row.RowState & DataControlRowState.Edit) > 0)
{
DropDownList ddlHours = (DropDownList)e.Row.FindControl("CmbHoursSpent");
ddlHours.DataSource = GenerateHoursList();
ddlHours.DataTextField = "NumberofHoursSpent";
ddlHours.DataValueField = "HoursSpent";
ddlHours.DataBind();
ddlHours.Items.FindByValue((e.Row.FindControl("LblHoursSpent") as Label).Text).Selected = true;
DropDownList ddlMinutes = (DropDownList)e.Row.FindControl("CmbMinutesSpent");
ddlMinutes.DataSource = GenerateMinutesList();
ddlMinutes.DataTextField = "NumberofMinutesSpent";
ddlMinutes.DataValueField = "MinutesSpent";
ddlMinutes.DataBind();
ddlMinutes.Items.FindByValue((e.Row.FindControl("LblMinutesSpent") as Label).Text).Selected = true;
}
}}
protected void GrdAttributesView_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
DropDownList ddlprice = (DropDownList)GrdAttributesView.Rows[e.RowIndex].FindControl("CmbHoursSpent");
String value = ddlprice.SelectedValue;
string MinutesSpent = (GrdAttributesView.Rows[e.RowIndex].FindControl("CmbMinutesSpent") as DropDownList).SelectedItem.Value;
}
Ideally in the RowUpdating method I should get the new value from the DropDown. but I don't understand why it gives the old value even though I select a different value.
I did a lot of reading and I saw different people using the same approach to get it done. But somehow it is not working for me.
Can someone help please?
I have a GridView with checkbox, dropdown and button as templatefields.
On button click I have to update the entire row in the data base.
This is my aspx:
<asp:GridView runat="server" ID="Gdv" AutoGenerateColumns="False" Font-Size="Small" CssClass="grid" BackColor="White" BorderWidth="0px" CellPadding="4" Width="100%" AllowSorting="True" SkinID="GVSalesManager" GridLines="none" AllowPaging="true" PageSize="10" PagerStyle-ForeColor="#0066cc" PagerStyle-CssClass="gvPagerCss" PagerStyle-Font-Underline="true" PagerStyle-Wrap="true"
OnPageIndexChanging="GdvCPRetailerMap_PageIndexChanging" OnRowDataBound="GdvCPRetailerMap_RowDataBound">
<Columns>
<asp:BoundField ReadOnly="true" HeaderText="S.No" DataField="S.No." SortExpression="SNo">
<ItemStyle HorizontalAlign="Center" Width="2%" />
<HeaderStyle HorizontalAlign="Center" Font-Bold="true" Width="2%"/>
</asp:BoundField>
<asp:TemplateField ItemStyle-Width="3%" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="chkRow" runat="server" OnCheckedChanged="chkRow_CheckedChanged" AutoPostBack="true"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField ReadOnly="true" HeaderText="Customer Id" ItemStyle-HorizontalAlign="Center" DataField="CustomerID" SortExpression="CustomerID">
<ItemStyle HorizontalAlign="Center" Width="10%" />
<HeaderStyle HorizontalAlign="Center" Font-Bold="true" Width="10%"/>
</asp:BoundField>
<asp:BoundField ReadOnly="true" HeaderText="Firm's Name" ItemStyle-HorizontalAlign="Center" DataField="Firm's Name" SortExpression="SNo">
<ItemStyle HorizontalAlign="Center" Width="20%" />
<HeaderStyle HorizontalAlign="Center" Font-Bold="true" Width="20%"/>
</asp:BoundField>
<asp:BoundField ReadOnly="true" HeaderText="Retailer Name" ItemStyle-HorizontalAlign="Center" DataField="Retialer Name" SortExpression="SNo">
<ItemStyle HorizontalAlign="Center" Width="20%" />
<HeaderStyle HorizontalAlign="Center" Font-Bold="true" Width="20%"/>
</asp:BoundField>
<asp:BoundField ReadOnly="true" HeaderText="Pesticide Licence No." ItemStyle-HorizontalAlign="Center" DataField="Pesticide Licence No" SortExpression="SNo">
<ItemStyle HorizontalAlign="Center" Width="10%" />
<HeaderStyle HorizontalAlign="Center" Font-Bold="true" Width="10%"/>
</asp:BoundField>
<asp:TemplateField HeaderText="Channel Partner-1" HeaderStyle-Font-Bold="true" ItemStyle-Width="10%" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:DropDownList ID="ddlCP1" Enabled="false" ToolTip="Please Click on the checkbox to change the prefered CP" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlCP1_SelectedIndexChanged"></asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Channel Partner-2" HeaderStyle-Font-Bold="true" ItemStyle-Width="10%" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:DropDownList ID="ddlCP2" Enabled="false" ToolTip="Please Click on the checkbox to change the prefered CP" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlCP2_SelectedIndexChanged"></asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="10%" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Button runat="server" ID="BtnUpdateRow" Text="Update" ToolTip="Update This Record?" OnClick="BtnUpdateRow_Click" BackColor="#336699" ForeColor="#ffffff"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
This is the updatebutton event
protected void BtnUpdateRow_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
GridViewRow grow = (GridViewRow)btn.NamingContainer;
//btn.
CheckBox chkbx = (CheckBox)grow.FindControl("chkRow");
if (chkbx.Checked != true)
{
labelErrormessage.Visible = true;
labelErrormessage.ForeColor = System.Drawing.Color.Red;
labelErrormessage.Text = "Please Check/Uncheck the CheckBox and Click Update";
return;
}
else
{
/*--Code to update the row's record in the edatabase.--*/
??
labelErrormessage.Visible = true;
labelErrormessage.ForeColor = System.Drawing.Color.Green;
labelErrormessage.Text = "Updated Succesfully";
return;
}
}
How do I read the row in which the button has been clicked and update its dropdownlist selected values in the database?
If you have some sort of identification data displayed in the gridview you could get the value from the row's cell like this grow.Cells[0].Text then find the record in the database and update its values.
You could also hide the id for example if this is information you dont want to show to the user. The row will still be located at index 0 but hidden.
Sample:
else
{
var record = queryDatabase(grow.Cells[0].Text);
//update record values
updateRecord(record);
labelErrormessage.Visible = true;
labelErrormessage.ForeColor = System.Drawing.Color.Green;
labelErrormessage.Text = "Updated Succesfully";
return;
}
I have a custom gridview and I use that grid in too many pages and I want to set the SortExpression text for all columns inside that grid in code behained ; as you see in the following code I have do that by overriding the OnRowDataBound eventhandler .
The problem is I can't access the evaluated datafield expression text ("START_WORK_DATE" in my case) for template Fields like what I did in BoundField
<eska:GridView ID="gvEmployees" runat="server" CssClass="new-grid" PageSize="20"
AllowSorting="true" AllowPaging="True"
AutoGenerateColumns="False" Width="100%"
GridContainer="tdEmployees" DataKeyNames="ID"
RowHoverCssClass="HoverRow" ShowCheckBox="True"
OnPageIndexChanging="gvEmployees_PageIndexChanging"
OnSelectedIndexChanged="gvEmployees_SelectedIndexChanged"
meta:resourcekey="gvEmployeesResource1">
<PagerSettings FirstPageImageUrl="~/App_Themes/Images/First.gif" LastPageImageUrl="~/App_Themes/Images/last.gif"
Mode="NextPreviousFirstLast" NextPageImageUrl="~/App_Themes/Images/Next.gif"
PreviousPageImageUrl="~/App_Themes/Images/prev.gif"></PagerSettings>
<SelectedRowStyle CssClass="SelectedRow"></SelectedRowStyle>
<Columns>
<asp:BoundField meta:resourcekey="BoundFieldResource1">
<ItemStyle Width="2%" />
<HeaderStyle Width="2%" />
<FooterStyle Width="2%" />
</asp:BoundField>
<asp:BoundField DataField="EMP_NO" HeaderText="Employee No"
meta:resourcekey="BoundFieldResource3">
<HeaderStyle Width="10%"></HeaderStyle>
<ItemStyle Width="10%"></ItemStyle>
<FooterStyle Width="10%" />
</asp:BoundField>
<asp:BoundField DataField="NAME" HeaderText="Name" meta:resourcekey="BoundFieldResource4">
<HeaderStyle Width="34%"></HeaderStyle>
<ItemStyle Width="34%"></ItemStyle>
<FooterStyle Width="34%" />
</asp:BoundField>
<asp:TemplateField HeaderText="Hiring Date" meta:resourcekey="TemplateFieldResource1">
<ItemTemplate>
<asp:Label runat="server"Text='<%# Convert.ToDateTime(DataBinder.Eval(Container,
"DataItem.START_WORK_DATE")).ToString("dd-MM-yyyy") %>'
ID="lblHiringDateGrid"></asp:Label>
</ItemTemplate>
<HeaderStyle Width="10%"></HeaderStyle>
<ItemStyle Width="10%"></ItemStyle>
<FooterStyle Width="10%" />
</asp:TemplateField>
<asp:BoundField DataField="PHONE1" HeaderText="Phone 1"
meta:resourcekey="BoundFieldResource5">
<HeaderStyle Width="10%"></HeaderStyle>
<ItemStyle Width="10%"></ItemStyle>
<FooterStyle Width="10%" />
</asp:BoundField>
<asp:BoundField DataField="Position_Name" HeaderText="Position"
meta:resourcekey="BoundFieldResource6">
<HeaderStyle Width="20%"></HeaderStyle>
<ItemStyle Width="20%"></ItemStyle>
<FooterStyle Width="20%" />
</asp:BoundField>
<asp:BoundField DataField="STATUS_DESC" HeaderText="Status"
meta:resourcekey="BoundFieldResource7">
<HeaderStyle Width="12%"></HeaderStyle>
<ItemStyle Width="12%"></ItemStyle>
<FooterStyle Width="12%" />
</asp:BoundField>
<asp:BoundField meta:resourcekey="BoundFieldResource8">
<ItemStyle Width="2%" />
<HeaderStyle Width="2%" />
<FooterStyle Width="2%" />
</asp:BoundField>
</Columns>
</eska:GridView>
Code behind:
protected override void OnRowDataBound(GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
for (int i = 0; i < this.Columns.Count; i++)
{
if (this.Columns[i] is BoundField)
{
if (((BoundField)(this.Columns[i])).DataField != string.Empty)
{
this.Columns[i].SortExpression = ((BoundField)(this.Columns[i])).DataField;
}
}
else if (this.Columns[i] is TemplateField)
{
// ???
}
}
}
}
You can do some thing like this. Set a header template with link button.
<asp:TemplateField>
<HeaderTemplate>
<asp:LinkButton ID="LinkButtonEmpName" runat="server" Text="Employee Name" CommandName="Sort" CommandArgument="Employees">
</asp:LinkButton>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="LabelEmployee" runat="server" Text='<%# Bind("Employees") %>'/>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TextBoxEmployee" runat="server"/>
</FooterTemplate>
And in row command event find command like this.
protected void grd_RowCommand(object sender, GridViewCommandEventArgs e){
if (e.CommandName.Equals("Sort"))
{
FilterExpression = e.CommandArgument.ToString() + " LIKE '%" + txtCaseNumber.Text + "%'";
BindGridView();
}}
See the complete example here.
http://www.codeproject.com/Questions/528664/HowplustoplusapplyplussortingplusinplusTemplateplu
i'm using a GridView and trying to sort and page it.
I have more than 20 rows on my DataBase, but the GridView just shows 10.
I set AllowPaging=true but noting happened.
Also I'm using AllowSorting = true and OnSorting="GridView_Sorting". But when I click on the header to sort the the content of that column, it does not enters on my OnSorting="GridView_Sorting" it goes right to the GridView1_RowCommand why ?
Sometimes it just give me this error:
Object reference not set to an instance of an object error
Here's my Code:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" style="font-family: Verdana, Arial, Sans-Serif;"
CssClass="gridview" OnSorting="GridView_Sorting"
AllowSorting ="True" AllowPaging="True" BackColor="#CCCCCC"
BorderStyle="Inset" BorderWidth="2px" BorderColor="GrayText"
CellPadding="1"
CellSpacing="5"
HeaderStyle-HorizontalAlign="Center"
OnRowDataBound="GridView1_RowDataBound"
ForeColor = "Black" RowStyle-CssClass="gridview"
OnRowCommand="GridView1_RowCommand">
<AlternatingRowStyle BackColor="#CCCCCC" />
<columns>
<asp:BoundField HeaderText="ID" DataField="id" SortExpression="id" />
<asp:BoundField HeaderText="PRIORIDADE" DataField="prioridade" ItemStyle-HorizontalAlign="Center" SortExpression="prioridade" SortExpression="prioridade" />
<asp:BoundField HeaderText="SITUAÇÃO" DataField="situacao" ItemStyle-HorizontalAlign="Center" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField HeaderText="RESPONSAVEL" DataField="responsavel" HeaderStyle-Width="65px" ItemStyle-HorizontalAlign="Center">
<HeaderStyle Width="65px" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField HeaderText="DATA DE CADASTRO" DataField="dt_cadastro" SortExpression="dt_cadastro" DataFormatString="{0:dd/MM/yyyy}" HeaderStyle-Width="60px"ItemStyleHorizontalAlign="Center" >
<HeaderStyle Width="60px" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField HeaderText="PREVISÃO DE TÉRMINO" DataField="previsao_termino" DataFormatString="{0:dd/MM/yyyy}" HeaderStyle-Width="60px"
ItemStyle-HorizontalAlign="Center">
<HeaderStyle Width="60px" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField HeaderText="PROJETO" DataField="projeto" ItemStyle-HorizontalAlign="Center"></asp:BoundField>
<asp:BoundField HeaderText="FUNCIONALIDADE" DataField="funcionalidade" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField HeaderText="CLUBE" DataField="clube" ItemStyle-HorizontalAlign="Center" />
<asp:TemplateField HeaderStyle-Width="70px" HeaderText="VISUALIZAR" >
<ItemTemplate>
<asp:Button ID="Btn_Visualizar" runat="server" Text="VISUALIZAR" CssClass="Btn_Grid" Font-Size="7pt" Font-Names="Verdana, Arial" OnClick="Btn_Visualizar_Click"CommandName="visualizar" CommandArgument="<%# ((GridViewRow)Container).RowIndex %>" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="66px" HeaderText="ALTERAR">
<ItemTemplate>
<asp:Button ID="Btn_Alterar" runat="server" Text="ALTERAR" CssClass="Btn_Grid" Font-Size="7pt" Font-Names="Verdana, Arial"CommandName="editar" CommandArgument="<%# ((GridViewRow)Container).RowIndex %>" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="66px" HeaderText="FEEDBACK">
<ItemTemplate>
<asp:Button ID="Btn_Feedback" runat="server" Text="ADICIONAR" CssClass="Btn_Grid" Font-Size="7pt" Font-Names="Verdana,Arial"CommandName="feedback" CommandArgument="<%# ((GridViewRow)Container).RowIndex %>" />
</ItemTemplate>
</asp:TemplateField>
</columns>
My CodeBehind:
protected void GridView_Sorting(object sender, GridViewSortEventArgs e)
{
string[] strSortExpression = ViewState["SortExpression"].ToString().Split(' ');
// If the sorting column is the same as the previous one,
// then change the sort order.
if (strSortExpression[0] == e.SortExpression)
{
if (strSortExpression[1] == "ASC")
{
ViewState["SortExpression"] = e.SortExpression + " " + "DESC";
}
else
{
ViewState["SortExpression"] = e.SortExpression + " " + "ASC";
}
}
// If sorting column is another column,
// then specify the sort order to "Ascending".
else
{
ViewState["SortExpression"] = e.SortExpression + " " + "ASC";
}
// Rebind the GridView control to show sorted data.
GridView1.DataSource = ch.BuscaTodosChamados();
GridView1.DataBind();
}
Add SortExpression attribute for each sortable column, informing its DataField.
I have one sharepoint custom page application which is rendering from a user control. In the user control page, i had used SPGridview for displaying data. My first column is Title Column (link button column), when the user click on the link, then one popup window will open with corresponding data. But the problem is the link button is not working properly. But this application is working as fine in asp.net application.
My code is shown below..
<asp:UpdatePanel runat="server" ID="UpdatePanel2">
<ContentTemplate>
<SharePoint:SPGridView ID="dgApplicationBox" CellPadding="0" Height="100%" runat="server"
ForeColor="Black" Font-Size="10px" Font-Names="Verdana" AutoGenerateColumns="False"
AllowPaging="True" Width="100%" BorderStyle="None" BorderWidth="0px" PageSize="10"
BorderColor="White" BackColor="White" OnRowDataBound="dgApplicationBox_RowDataBound"
DataKeyNames="ApplicationID" OnSelectedIndexChanged="dgApplicationBox_SelectedIndexChanged"
OnPageIndexChanging="dgApplicationBox_PageIndexChanging" CssClass="ms-listviewtable"
AlternatingRowStyle-CssClass="ms-alternating">
<SelectedRowStyle Font-Bold="True" ForeColor="Black" BackColor="#CE5D5A"></SelectedRowStyle>
<EditRowStyle Font-Size="10px" Font-Names="Verdana,Arial,Helvetica,sans-serif"></EditRowStyle>
<HeaderStyle Font-Size="11px" Height="20px" Font-Bold="True" ForeColor="Black" BackColor="#E7E8EC">
</HeaderStyle>
<PagerStyle HorizontalAlign="Center" ForeColor="#414E61" Font-Size="5px" Font-Names="arial"
Height="10px" BackColor="#EBF3FF"></PagerStyle>
<RowStyle />
<Columns>
<asp:TemplateField HeaderText="Title" HeaderStyle-CssClass="ms-vb">
<ItemTemplate>
<asp:LinkButton ID="lbtnSubject"
Text='<%# Bind("UDF5") %>' runat="server" OnClick="lbtnSubject_Click"></asp:LinkButton>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" CssClass="ms-vh2" Font-Bold="true" />
<ItemStyle HorizontalAlign="Left" CssClass="ms-vb2" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Request No.">
<ItemTemplate>
<asp:Label ID="lblReqNo" Text='<%# Bind("UDF1") %>' runat="server" />
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" CssClass="ms-vh2" Font-Bold="true" />
<ItemStyle HorizontalAlign="Left" CssClass="ms-vb2" />
</asp:TemplateField>
<asp:BoundField DataField="CreatedOn" HeaderText="Created On" DataFormatString="{0:MM/dd/yyyy}"
HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left">
<HeaderStyle CssClass="ms-vh2" Font-Bold="true"></HeaderStyle>
<ItemStyle CssClass="ms-vb2"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="Name" HeaderText="Form Type" HeaderStyle-HorizontalAlign="Left"
ItemStyle-HorizontalAlign="Left">
<HeaderStyle CssClass="ms-vh2" Font-Bold="true"></HeaderStyle>
<ItemStyle CssClass="ms-vb2"></ItemStyle>
</asp:BoundField>
<asp:TemplateField HeaderText="History">
<HeaderStyle CssClass="ms-vh2" Font-Bold="true"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="21px" CssClass="ms-vb2">
</ItemStyle>
<ItemTemplate>
<asp:LinkButton ID="lbtnView" runat="server" OnClick="lbtnView_Click" >View</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Application Id" Visible="False">
<ItemTemplate>
<asp:Label ID="lblApplicationId" runat="server" Text='<%# Bind("ApplicationId") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" CssClass="ms-vh2" Font-Bold="true" />
<ItemStyle HorizontalAlign="Left" CssClass="ms-vb2" />
</asp:TemplateField>
</Columns>
</SharePoint:SPGridView>
</ContentTemplate>
</asp:UpdatePanel>
when the user click on the link button, this code will works..
try
{
clearSession();
Session["DigitalSignature"] = null;
Button btnDetails = sender as Button;
DataTable dt = (DataTable)dgApplicationBox.DataSource;
GridViewRow gvRow = (GridViewRow)(sender as LinkButton).Parent.Parent;
Session["AppId"] = ((Label)gvRow.FindControl("lblApplicationId")).Text;
string subject = ((LinkButton)gvRow.FindControl("lbtnSubject")).Text;
WFInfo objWFInfo = new WFInfo();
objWFInfo.InitWorkflowProperty(Convert.ToInt32(Session["AppId"].ToString()), Session["CurrentUser"].ToString());
Session["FormId"] = objWFInfo.FormID.ToString();
string strFilname = objWFInfo.GetFormName(objWFInfo.ApplicationCategoryID.ToString());
string WindowName = strFilname;
strFilname += ".aspx";
Session["CategoryId"] = objWFInfo.ApplicationCategoryID.ToString();
//pnlSubmitModal_ModalPopupExtender.Show();
ScriptManager.RegisterStartupScript(this, this.GetType(), "starScript", "popUpWindow('" + strFilname + "?tittle=" + subject + "', 800, 690,'" + WindowName + "');", true);
this.Controls.Add(new LiteralControl("<script>alert('hi');</script>"));
if (Session["CurrentUser"] != null)
{
ApplicationForm objApplication = new ApplicationForm();
objApplication.markRead(Convert.ToInt32(Session["AppId"].ToString()), Session["CurrentUser"].ToString());
}
bindFolderData();
}
If i click on the link button, there will be only post back occuring. but not the popup window open.. Please help me for resolving this problem. thanks in advance..
Have you checked to see if you're receiving a javascript error on the click?
Have you tried setting UpdatePanel2's UpdateMode="Conditional" and then adding Triggers? (button click)
Like this sample:
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="lbtnSubject" EventName="Click" />
</Triggers>