|
Hi,
Case:
1) Datagrid Bound columns generated at runtime and populated from the dataset.
2) Datagrid contains a select button. When the select button is pressed a new report is generated.
Language: Visual Studio 2.0, ASP.Net, C#
Problem: During the first page_load grid is populated properly but when it is postback Datagrids items and cells are not visible in the select buttons itemcommand method.
By referring the articles in the google i came to know that i should not be using page_load, instead i should call the method in the initializecomponent() , but since i am working on .Net 2.0 it does not have initializecomponent method. I have also tried PreLoad and its not working.
Please find below my sample code so that u get a better idea.
--Sample Code Starts Here
protected void Page_PreLoad(object sender, EventArgs e)
{
if (!IsPostBack)
{ getdata(); }
.....
}
public virtual void grdvwCheckbox_ItemCommand(object s, DataGridCommandEventArgs e)
{
if (e.CommandName == "Select")
{
e.Item.BackColor = System.Drawing.Color.Wheat;
DataGrid dg = (DataGrid) s;
.........
}
}
public void getdata()
{
DataSet ds = new DataSet();
string rptDetails;
rptDetails = txtRptDetails.Text;
GridReports objBO = new GridReports();
ds = (DataSet)objBO.GridData(rptDetails);
grdvwCheckbox.AutoGenerateColumns = false;
foreach (DataColumn c in ds.Tables[0].Columns)
{
grdvwCheckbox.Columns.Add(CreateBoundColumns(c));
}
...................
}
--Sample Code Ends Here
Hope this helps u to help me.
If u have any working sample code in .Net 2.0 where Bound columns are created at runtime and ItemCommand event is fired then please forward it to me.
A quick reply will be really helpful.
Please feel free to revert in case of any clarification.
Thanks!
|
|
|
|
|
If it is not working on preload, try Init
protected void Page_Init(object sender, EventArgs e)
{
Initialize your control here
}
|
|
|
|
|
Thanks for your reply,
It is not working with Init. If u have any working sample code in .Net 2.0 where Bound columns
are created at runtime and ItemCommand event is fired then it might help.
Regards,
Anees
|
|
|
|
|
Anees Mitha wrote: It is not working with Init.
It will if you remove postback checking. Remove !IsPostBack when calling getData();
|
|
|
|
|
Great show sir, it does work. Thanks.
But the only problem now is that for every ItemCommand event it will make a round to the database which will be very costly in my case where the reports are huge. So apart from this is there any other way round to achieve the same results.
Anyways i really appreciate your help and support. Thanks a ton.
Regards,
Anees
|
|
|
|
|
Anees Mitha wrote: it will make a round to the database which will be very costly in my case
You can cache the dataset. This will avoid round trip to server
|
|
|
|
|
|
I created a class which checks session and redirects to login page. My class looks like this. This class inherits Page class to get access to session object.
public class CAuthentication:System.Web.UI.page
{
public CAuthentication()
{
if ( Session["login"] == null )
Response.Redirect("expired.aspx");
}
}
My ASPX.CS looks like
public partial class MyPage:CAuthentication
{
}
This is not working. I am getting error "session can't be used inside a class" . What is wrong here ? Normally codebehind file used to inherit System.Web.UI.Page , Instead of this I inherited this in my CAuthentication class. Where I am going wrong ?
|
|
|
|
|
Please check it with HttpContext.Current.Session["login"].
|
|
|
|
|
Nicejith wrote: HttpContext.Current.Session["login"].
Thanks, But still it shows Object Reference error.,
|
|
|
|
|
N a v a n e e t h wrote: Normally codebehind file used to inherit System.Web.UI.Page, Instead of this I inherited this in my CAuthentication class.
Why do you need to do this??
For your session check, you can use your existing class and I suggest you should pass the Session object to your session checker function and then check the sessions and proceed to redirection. Like
<br />
public CheckAuthentication(System.Web.SessionState.HttpSessionState oSession ) <br />
{ if ( oSession["login"] == null )<br />
Response.Redirect("expired.aspx"); }<br />
Also pass the response object the same way.
NOTE: Remove the inheritance from your class
Mubashir
Software Architect
Storan Technologies Inc, USA
Every job is a self portrait of the person who did it.
|
|
|
|
|
_mubashir wrote: Why do you need to do this??
Thanks, I need to do this because, this simplifies my job than passing Response , and SessionState object to Checking functions. In all my pages I need to check this session. So i thought it's better to go for inheritance method. May be that is a bad approach, but still it has to work when we think the program flow. Any Idea on what is going wrong here ?
|
|
|
|
|
Hi, I have been working on this for over two weeks and its not working. I don't know what else to do since I'm really green at this. I'm trying to display binary data from a database using Response.Write(). Please take a look to see where I went wrong, thank you in advance for your help.
Private Sub ListBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim DBConn As OdbcConnection
Dim DBCommand As OdbcCommand
Dim DS As New DataSet
If Not LBoxProfessions.SelectedItem Is Nothing Then
DBConn = New OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=myDB;Database=myDB;User=myUser;Password=myPW;Option=3;")
DBCommand = New OdbcCommand("Select ResumeID,Resumes,DocType, from tb_content where Professions = '" & LBoxProfessions.SelectedItem.Text & "' Limit 10 Offset 10", DBConn)
DBConn.Open()
Dim AD As OdbcDataReader = DBCOmmand.ExecuteReader()
If (AD.Read()) Then
Dim contentLength As Integer = Convert.ToInt32(AD.GetBytes(0, 0, Nothing, 0, Integer.MaxValue))
Dim buffer As Byte() = New Byte(contentLength - 1) {}
AD.GetBytes(0, 0, buffer, 0, contentLength)
'Resumes is the field in the database table that holds the documents
Response.AddHeader("Content-Disposition", "attachment;filename=Resumes")
'DocType is the field that holds the mime types
Response.ContentType = DirectCast(AD("DocType"), String)
Response.BinaryWrite(buffer)
Response.End()
End If
DBConn.Close()
End If
End Sub
-- modified at 5:11 Saturday 4th August, 2007
|
|
|
|
|
What is your question ? Why don't you look up a column to read your binary data ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Basically I'm doing what you've suggested last week. First I stored the mime types of each binary file in a field called DocType in my database. So if an image file is stored in the Resumes field it would have a mime type of "image/gif" etc. Then after I connect to the database I use the datareader to read the data then put the data into a byte array. Then I use the following two lines to determine the name of the file to be displayed and to determine its content type.
'Resumes is the field in the database table that holds the documents
Response.AddHeader("Content-Disposition", "attachment;filename=Resumes")
'DocType is the field that holds the mime types
Response.ContentType = DirectCast(AD("DocType"), String)
I have a typo in my code and its "filename=ResType" I've already changed that to Resume. Don't you run away after giving just a vague response Christian 'cause I really need your help lol. When a list item is selected its suppose to show a file but its not working, I'm very frustrated right now. Thanks for replying
-- modified at 5:29 Saturday 4th August, 2007
|
|
|
|
|
Yeah, but when you fille the buffer variable, you don't use a column name to get to the data in question, you just do a read on the row itself.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi,
I have made a small application which process Mail Items (Notes Items) and save its properties in database. I have used outlook object model.It is working fine but for one message it gives an error as below.
"Cannot open this item.Out of memory or system resources. Close some windows or programs and try again."
Even this message also can't be open in outlook. I don't want this error comes while processing.So I don't want to process this message from my application. Is there any property of the message from which I can detect that it can't be processed? If any one knows please reply.
Thanks,
Pavan
|
|
|
|
|
hi,
I am using MS .NET 1.1
i want to create an image gallery ..
which control should i use to do this??
means i want to show 5 images in first row and next 5 in second and so on...
All I ever wanted is what others have.... CrazySanker
|
|
|
|
|
I'd just create a base control, have a collection of images, and draw them myself.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
hi ,
Thanx for ur reply
I know, how to create a custome control.I created and used it in .net 2.0 .
But this is first time time I am trying in .NET 1.0.Here a use a class to create a custome control and try to register it in my web page.
But I am failed to register it.
I used this line of code to register in my web page
<br />
<%@ Register TagPrefix="Mcntrl" Namespace="comedia.MediaPlayerControl">
but i didnt get this control inside my body tag.
i tried like this
<br />
<Mcntrl:MediaPlayerControl ID="MyMediaPlayer" runat="server"> </Mcntrl:MediaPlayerControl><br />
but it show error creating control in design view.
wat should i do.
There is no compliation error.
And I created it in .Net 2.0 and it works Fine.
Expect ur help or any links.
Thankx
All I ever wanted is what others have.... CrazySanker
|
|
|
|
|
OK, sorry, I didn't spot that this was the ASP.NET forum. A repeater is the way to do this. You can use a repeater to build a control that builds a table, and that adds the tr tag for a new row after a specific number of images. Of course, they need to exist as files and then you can show them in IMG tags.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi,
I use a datagrid .the code is look like..
<br />
<br />
<asp:TemplateColumn><br />
<ItemStyle HorizontalAlign="Center" Width="10%" VerticalAlign="Top"></ItemStyle><br />
<ItemTemplate><br />
<asp:Image Width="70" Height="70" ImageUrl='<%#ShowImage(Convert.ToString(DataBinder.Eval(Container.DataItem, "EmployeeImage").ToString() ))%>' Runat=server ID="Image1"/><br />
</ItemTemplate><br />
</asp:TemplateColumn><br />
<asp:TemplateColumn HeaderText=" Name And Designation"><br />
<HeaderStyle HorizontalAlign="Center"></HeaderStyle><br />
<ItemStyle Font-Size="8pt" HorizontalAlign="Justify" Width="38%" VerticalAlign="Top" BackColor="#FFFFCC"></ItemStyle><br />
<ItemTemplate><br />
<br />
<%#DataBinder.Eval(Container.DataItem, "EmployeeName")%><br />
<br />
<br><br />
<%#DataBinder.Eval(Container.DataItem, "Designation")%><br />
<br><br />
<%#DataBinder.Eval(Container.DataItem, "EmailAddress")%><br />
<br><br />
Mob: <%#DataBinder.Eval(Container.DataItem, "MobileNo")%><br />
</ItemTemplate><br />
</asp:TemplateColumn><br />
<br />
In repeater, i draw a table in item template.. but how i fix after five image it ll go to next row..
in rpeater it will gro horizontally..
can you help me???
All I ever wanted is what others have.... CrazySanker
|
|
|
|
|
Hi buddy,
if u aware of Grid viw control than its the best thing to disply the images as u want.
Try and if u face problem i m the solution
Hello Forum
Always be in touch to help about the topic ASP.NET
|
|
|
|
|
Hi Friend,
Thankx for ur reply.
I am not sure, is it Grid view control is available in .NET 1.0??
All I ever wanted is what others have.... CrazySanker
|
|
|
|
|
Nope. A DataGrid is, but you'd need five images per row to make that work. A repeater is better.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|