Gridview not visible even after binding - c#

I got stucked to some weird condition where I have a gridview inside a ajax toolkit tabcontainer. On tab index change i am binding grid. But nothing happend. Grid is not appearing. I have check the following
Viewstate
Visibility of grid
Visibility of the parent table.
Data is coming from the method
visibility of the tab panel
Even i have debugged and added watch to check if its getting null before loading the page.
Please help me out
** BELOW IS THE UPDATED CODE**
<HTMLCode>
<Toolkit:TabPanel HeaderText="Pending Challans" ID="tpPendingChallan" runat="server" Height="200px" >
<ContentTemplate>
<table style="width: 100%">
<tr>
<td>
<asp:GridView ID="gvPendingChallans" runat="server" AutoGenerateColumns="True" CellPadding="4" Width="100%" OnPageIndexChanging="gvPendingChallans_PageIndexChanging"
OnRowCommand="gvPendingChallans_RowCommand" AllowPaging="True" GridLines="None">
</asp:GridView>
</td>
</tr>
</table>
</ContentTemplate>
</Toolkit:TabPanel>
</HTMLCode>
========================================================================
<C#>
private void BindPendingChallans()
{
var dat = JobCardManager.DisplayChallan();
gvPendingChallans.DataSource = dat;
gvPendingChallans.DataBind();
}
protected void tcMembers_ActiveTabChanged(object sender, EventArgs e)
{
if(tcMembers.ActiveTabIndex == 6)
{
BindPendingChallans();
}
}
</C#>

Sorry for miss interpretation of your code with my first answer. I thought that it just a simple population of grid view, but as review I found that you are using the Ajax Toolkit library and your grid is inside the tab selection. You can try this:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="Toolkit" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head2" runat="server">
<title>Untitled Page</title>
<style type="text/css">
.style1
{
font-family: Arial;
color: #3399FF;
}
</style>
</head>
<body class="style1">
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager2" runat="server" EnablePageMethods="true" />
<div>
<asp:UpdatePanel ID="upMember" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<table cellpadding="1" cellspacing="4" border="0" width="100%">
<tr>
<td>
<Toolkit:TabContainer ID="tcMembers" runat="server" AutoPostBack="true"
ActiveTabIndex="0" onactivetabchanged="tcMembers_ActiveTabChanged">
<Toolkit:TabPanel HeaderText="Pending Challans" ID="tpPendingChallan" runat="server"
Height="200px">
<ContentTemplate>
<asp:GridView ID="gvPendingChallans" runat="server" AutoGenerateColumns="True" CellPadding="4"
Width="100%" OnPageIndexChanging="gvPendingChallans_PageIndexChanging" OnRowCommand="gvPendingChallans_RowCommand"
AllowPaging="True" GridLines="None">
</asp:GridView>
</ContentTemplate>
</Toolkit:TabPanel>
<Toolkit:TabPanel HeaderText="Pending 2" ID="tpPending2" runat="server"
Height="200px">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="True" CellPadding="4"
Width="100%" OnPageIndexChanging="gvPendingChallans_PageIndexChanging" OnRowCommand="gvPendingChallans_RowCommand"
AllowPaging="True" GridLines="None">
</asp:GridView>
</ContentTemplate>
</Toolkit:TabPanel>
</Toolkit:TabContainer>
</td>
<td width="2%">
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
Then in your code behind:
protected void Page_Load(object sender, EventArgs e)
{
upMember.Update();
}
private void BindPendingChallans()
{
//var dat = JobCardManager.DisplayChallan();
//gvPendingChallans.DataSource = dat; gvPendingChallans.DataBind();
}
protected void tcMembers_ActiveTabChanged(object sender, EventArgs e)
{
if (tcMembers.ActiveTabIndex == 6)
{
BindPendingChallans();
}
}
protected void gvPendingChallans_PageIndexChanging(object sender, GridViewPageEventArgs e){
}
protected void gvPendingChallans_RowCommand(object sender, GridViewCommandEventArgs e){
}
Note: That in you 'tcMembers_ActiveTabChanged' you had specify tab index 6
The Tab index begins with 0. Maybe you can adjust it depending the number of
you Intended tab....
Regards,

Related

ASP.NET & C# : gridview select does no action

Why is GridView1_SelectedIndexChanged not working?
I'm learning ASP.NET on my own (which means I learn through youtube), using VS 2015.
I created a grid of items and want to show the selected item in a textbox, but code doesn't do any change.
I created an empty project, added a masterpage and default page, and just added a text and grid, scriptmanager updatepanel contenttemplate.
Whenever I click select on any row from the grid textbox is still empty.
MasterPage.master:
<%# Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
Default.aspx:
<%# Page Title="" enableeventvalidation="true" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<style type="text/css">
.auto-style1 {
width: 100%;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table class="auto-style1">
<tr>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>
<asp:GridView ID="GridView1" runat="server" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:CommandField ButtonType="Button" ShowSelectButton="True" />
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
Default.aspx.cs:
using System;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable tbl = new DataTable();
tbl.Columns.Add("serial");
for (int i = 0; i < 4; i++)
{
DataRow row = tbl.NewRow();
row[0] = i + 1;
tbl.Rows.Add(row);
}
GridView1.DataSource = tbl;
GridView1.DataBind();
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox1.Text = GridView1.SelectedRow.Cells[0].Text;
}
}
You are selecting the wrong cell on the SelectedIndexChanged method.
The first Cell (index 0) contains the button, so you want the second cell (index 1).
You should place a breakpoint on the method and see for yourself what other properties are filled in the GridView.

how to export images to excel from gridview in asp.net?

I have a ASPxGridView consist of a image column. When I click the ExportToPDF,images are shown in pdf. But if I click the ExportToXls, images are not shown in the excel. What is the problem ?
I use Devexpress 14.2 in visual studio.
P.S. = Images in gridview are different sizes.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td style="padding-right: 4px">
<dx:ASPxButton ID="btnPdfExport" runat="server" Text="Export to PDF" OnClick="btnPdfExport_Click" />
</td>
<td style="padding-right: 4px">
<dx:ASPxButton ID="btnXlsExport" runat="server" Text="Export to XLS" OnClick="btnXlsExport_Click" />
</td>
<td style="padding-right: 4px">
<dx:ASPxButton ID="btnXlsxExport" runat="server" Text="Export to XLSX" OnClick="btnXlsxExport_Click" />
</td>
<td style="padding-right: 4px">
<dx:ASPxButton ID="btnRtfExport" runat="server" Text="Export to RTF" OnClick="btnRtfExport_Click" />
</td>
<td>
<dx:ASPxButton ID="btnCsvExport" runat="server" Text="Export to CSV" OnClick="btnCsvExport_Click" />
</td>
</tr>
</table>
<dx:ASPxGridView ID="Grid" runat="server" AutoGenerateColumns="False" DataSourceID="XmlDataSource1">
<Columns>
<dx:GridViewDataTextColumn FieldName="Common_Name" Caption="Common name" />
<dx:GridViewDataTextColumn FieldName="Species_Name" Caption="Species name" />
<dx:GridViewDataImageColumn FieldName="ImagePath" Caption="Image">
<PropertiesImage>
<ExportImageSettings Width="180" Height="120" />
</PropertiesImage>
</dx:GridViewDataImageColumn>
</Columns>
<SettingsPager PageSize="30" />
</dx:ASPxGridView>
<dx:ASPxGridViewExporter ID="GridExporter" runat="server" GridViewID="Grid" OnRenderBrick="GridExporter_RenderBrick" />
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/Intranet/denemebru/Fishes.xml" />
</form>
</body>
</html>
public partial class Intranet_denemebru_RaporDeneme2 : System.Web.UI.Page
{
protected void GridExporter_RenderBrick(object sender, ASPxGridViewExportRenderingEventArgs e)
{
var dataColumn = e.Column as GridViewDataColumn;
if (dataColumn != null && dataColumn.FieldName == "ImagePath" && e.RowType == GridViewRowType.Data)
e.ImageValue = GetImageBinaryData(e.Value.ToString());
}
protected void btnPdfExport_Click(object sender, EventArgs e)
{
GridExporter.WritePdfToResponse();
}
protected void btnXlsExport_Click(object sender, EventArgs e)
{
GridExporter.WriteXlsToResponse();
}
protected void btnXlsxExport_Click(object sender, EventArgs e)
{
GridExporter.WriteXlsxToResponse();
}
byte[] GetImageBinaryData(string relativePath)
{
string path = Server.MapPath(relativePath);
return File.Exists(path) ? File.ReadAllBytes(path) : null;
}
}

how to find checkbox where checked in repeater in asp.net?

i want when click btndelete , every checkbox where chechek in repeater1 to get value of column(titr) in same row, but i dont find which checkbox checked and dont access to value of column(titr)
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table>
<tr>
<td> </td>
<td>subject</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:CheckBox ID="CheckBox1" runat="server" />
</td>
<td id="checkvalue" >
<%# Eval("titr") %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate></table></FooterTemplate>
</asp:Repeater>
<asp:Button ID="btndelete" runat="server" Text="delete" OnClick="btndelete_Click" />
.cs code is :
protected void btndelete_Click(object sender, EventArgs e)
{
}
You could get a list of repeaterItems for each row in which the checkbox is checked using linq such that:
List<RepeaterItem> selectedItems = Repeater1.Items.Cast<RepeaterItem>().Where(x => ((CheckBox)x.FindControl("CheckBox1"))
.Checked).ToList();
You could then iterate through the list and get the value of titr for each of the selected rows, but you would have to set some server control equal to "titr" when you bind the control, like:
<asp:literal id="literal1" runat="server"><%# Eval("titr") %></asp:literal>
That way you could go find the value later when you iterate through the list, like this:
List<string> titrValues = selectedItems.Select(t => ((Literal)t.FindControl("literal1).Text));
You may have to do some tweaking, but that should get you the values of titr for each row with a selected value.
Aspx Code:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Repeater ID="Repeater1" runat="server" >
<ItemTemplate>
<div>
<asp:CheckBox ID="CategoryID" runat="server" Text='<%# Eval("val") %>' />
</div>
</ItemTemplate>
</asp:Repeater>
<asp:Button Text="Click" OnClick="Button2_Click" runat="server" />
</form>
</body>
</html>
CS Code:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("val", typeof(string));
for (int i = 0; i < 10; i++)
dt.Rows.Add("testing" + i.ToString());
Repeater1.DataSource = dt;
Repeater1.DataBind();
}
}
protected void Button2_Click(object sender, EventArgs e)
{
string Rpt = "Repeater Items Checked:<br />";
for (int i = 0; i < Repeater1.Items.Count; i++)
{
CheckBox chk = (CheckBox)Repeater1.Items[i].FindControl("CategoryID");
if (chk.Checked)
{
Rpt += (chk.Text + "<br />");
}
}
Response.Write(Rpt);
}
You can also use break point to check the get values....
Refrenced By: http://www.codeproject.com/Questions/534719/GetplusSelectedplusCheckboxesplusinplusASPplusRepe

Enable tabpanel in tabcontainer

I have a tabcontainer with two tabs. The first tab contains a textbox, while the second tab contains a panel.
I want the second tab to be disabled at first page load, and I want it to become enabled as soon as the user enters an input in the textbox in tab1. When textbox in tab1 is emptied again, the second tab should again be disabled.
I tried the following code, but the second tab remains disabled no matter what.
Any help would be appreciated. Thank you!
aspx
<asp:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="4" HeaderText=""
Height="578px" Width="900px" TabStripPlacement="Top" ScrollBars="None" UseVerticalStripPlacement="false"
VerticalStripWidth="120px" BackColor="White" BorderColor="White" Style="margin-right: 84px">
<asp:TabPanel ID="TabPanel1" runat="server">
<HeaderTemplate>
General
</HeaderTemplate>
<ContentTemplate>
<asp:UpdatePanel ID="TestUpdatePanel" runat="server">
<ContentTemplate>
<table style="height: 247px; width: 100%;">
<tr>
<td>
<asp:TextBox ID="HorizonTextBox" runat="server" OnTextChanged="HorizonTextBox_TextChanged"
AutoPostBack="True"></asp:TextBox>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel2" runat="server">
<HeaderTemplate>
Dashboard
</HeaderTemplate>
<ContentTemplate>
<asp:Button ID="RunSimulationButton" runat="server" Text="Run Simulation" OnClick="RunSimulationButton_OnClick" />
<br />
<br />
<asp:Panel ID="PlotPanel" runat="server">
</asp:Panel>
</ContentTemplate>
</asp:TabPanel>
aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
TabContainer1.ActiveTabIndex = 0;
TabPanel2.Enabled = false;
}
}
protected void HorizonTextBox_TextChanged(object sender, EventArgs e)
{
if(HorizonTextBox.Text != "")
{
TabPanel2.Enabled = true;
}
}
you may need to enclose whole tab container into updatepanel to allow update panel enable/disable child controls

Change ASPxGridView SettingsLoadingPanel text dynamically

I need to change ASPxGridView SettingsLoadingPanel dynamically (from code behind if is possible).
For example, when I clicked on checkbox I want text to be 'selecting...' and after click the button to see text 'loading...'
Thanks!
You can use ASPxClientLoadingPanel method. And also .Shov() method invokes the loading panel.
<dxlp:ASPxLoadingPanel ID="ASPxLoadingPanel1" runat="server" ClientInstanceName="lp">
</dxlp:ASPxLoadingPanel>
<dxe:ASPxButton ID="btnShow" runat="server" AutoPostBack="False"
Text="Show" ClientInstanceName="button" >
<ClientSideEvents Click="function(s, e) {
lp.Show();
}" />
</dxe:ASPxButton>
<dxe:ASPxButton ID="btnHide" runat="server" AutoPostBack="False"
Text="Hide" ClientInstanceName="button" >
<ClientSideEvents Click="function(s, e) {
lp.Hide();
}" />
</dxe:ASPxButton>
Also you can find a demo in this link.
ASPX
<%# Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Example.aspx.cs"
Inherits="ASPxLoadingPanel_Example" %>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentHolder" runat="Server">
<dx:ASPxCallback ID="ASPxCallback1" runat="server" ClientInstanceName="Callback">
<ClientSideEvents CallbackComplete="function(s, e) { LoadingPanel.Hide(); }" />
</dx:ASPxCallback>
<div class="BottomPadding">
<dx:ASPxCheckBox ID="ASPxCheckBox1" runat="server" AutoPostBack="true" Checked="True"
Text="Display the ASPxLoadingPanel over a specific control">
</dx:ASPxCheckBox>
</div>
<table id="Panel" style="border: Dashed 1px Gray; height: 125px; width: 60%; margin: 30px 20%">
<tr>
<td align="center" valign="middle">
<dx:ASPxButton ID="ASPxButton1" runat="server" Text="Show Loading Panel" AutoPostBack="False">
<ClientSideEvents Click="function(s, e) {
Callback.PerformCallback();
LoadingPanel.Show();
}" />
</dx:ASPxButton>
</td>
</tr>
</table>
<dx:ASPxLoadingPanel ID="LoadingPanel" runat="server" ClientInstanceName="LoadingPanel"
Modal="True">
</dx:ASPxLoadingPanel>
</asp:Content>
C#
using System;
using System.Threading;
using System.Web.UI;
public partial class ASPxLoadingPanel_Example : Page {
protected void Page_Load(object sender, EventArgs e) {
if(IsCallback) {
// Intentionally pauses server-side processing,
// to demonstrate the Loading Panel functionality.
Thread.Sleep(500);
}
LoadingPanel.ContainerElementID = ASPxCheckBox1.Checked ? "Panel" : "";
}
}

Categories

Resources