|
I can't seem to get to display the results from a gridview. The code compiles but it only shows 'no records' when I display the webpage. Any help would be greatly appreciated. I am thinking that maybe the information for 'typename' and 'dataojecttypename' are incorrect. What exactly should these two contain?
Here is my code in part:
[DataObjectMethod(DataObjectMethodType.Select)]
public static List<userdata> getAllUsers()
{
MySqlCommand cmd = new MySqlCommand();
DB_Connection conn = new DB_Connection();
try
{
cmd.Connection = (MySqlConnection)conn.DBConnect();
cmd.CommandText = "getAllUsers";
cmd.CommandType = CommandType.StoredProcedure;
cmd.ExecuteNonQuery();
MySqlDataReader dr;
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
List<userdata> userList = new List<userdata>();
while (dr.Read())
{
UserData user = new UserData();
user.UserID = Convert.ToString(dr["User_ID"]);
user.UserLastName = Convert.ToString(dr["User_Last_Name"]);
user.UserFirstName = Convert.ToString(dr["User_First_Name"]);
}
dr.Close();
return userList;
<asp:objectdatasource id="ObData" runat="server" typename="users"
="" oldvaluesparameterformatstring="original_{0}" selectmethod="getAllUsers" dataobjecttypename="userdata">
<asp:gridview id="GridView1" action="databind" runat="server" datasourceid="ObData" autogeneratecolumns="False" emptydatatext="<b>No Records</b>" allowpaging="True" datekeynames="User_Id">
<columns><asp:boundfield datafield="User_Id" headertext="User_Id" sortexpression="User_Id">
<asp:boundfield datafield="User_Last_Name" headertext="LastName" sortexpression="User_Last_Name">
<asp:boundfield datafield="User_First_Name" headertext="FirstName" sortexpression="User_First_Name">
|
|
|
|
|
Your method returns userList, which has only been instantiated and has not been initialized. You might want to put some values in that list for the datagrid to bind to. I'm assuming thats what you're binding the datagrid with.
Next time, please put the code in <pre></pre> tags to make it easier to read.
|
|
|
|
|
|
List userList = new List();
You create an instance of a List object but you don't add any items to it.
while (dr.Read())
{
UserData user = new UserData();
user.UserID = Convert.ToString(dr["User_ID"]);
user.UserLastName = Convert.ToString(dr["User_Last_Name"]);
user.UserFirstName = Convert.ToString(dr["User_First_Name"]);
}
For each iteration of the loop, you create a new UserData object and populate it with data from the current record returned by the DataReader. However you don't do anything with each UserData object. After each iteration of the loop the UserData object will go out of scope and be lost. You should add these objects to some sort of collection data structure if you want to retain them.
Regards
Paul
|
|
|
|
|
Thanks, Paul. You pointing this out made me realize that I had forgotten a very important line of code, mainly: userlist.add(user);
It is working like a charm now.
|
|
|
|
|
I am developing an home page which can be access from 5 countries. Based on user location (which i don't know it could be Country A, B, C , D or E) i need to change home page accordingly. By default we will have country A.
My boss says try to explore culture...but i have no idea for the same...Could you please show some directon....
Thanks
Thanks
|
|
|
|
|
You can create a CultureInfo object from a culture identifier or culture name. Example:
CultureInfo culture = new CultureInfo("en-GB");
You just have to find out what culture the user preferres. The Accept-Language header in the HTTP headers might be one way to find this out.
You use the CultureInfo object whenever you format any data that is culture dependant, for example in the string.Format or double.ToString methods. Example:
labelPrice.Text = price.ToString("C2", culture);
---
single minded; short sighted; long gone;
|
|
|
|
|
I am using this
Response.Write(CultureInfo.CurrentCulture.ThreeLetterISOLanguageName);
and everytime is shows USA....I tried to change the settings from control panel-->regional and language options....
But no luck!!
thanks
|
|
|
|
|
Amit Kumar G wrote: I am using this
Response.Write(CultureInfo.CurrentCulture.ThreeLetterISOLanguageName);
and everytime is shows USA...
Yes, of course. You are showing the culture that the server is using.
---
single minded; short sighted; long gone;
|
|
|
|
|
Check the dataset that is returned from from the fill method
"Session("Formats") = dsFormat"
Don't store your dataset in a session variable, it is bad practice and a performance drain.
"selectText = "select format from Formats where fID='" + num + "' and format <> 'Other'"
Don't use in-line sql. Use stored procs, or at least parameterized commands.
And don't hard code the connection string, even if it is a test app, get in the habit of using good programming practices.
only two letters away from being an asset
|
|
|
|
|
Thank you Mark, I will try changing the session variables thing later, once I get this to work.
How can I check if the dataset returned is empty or not. Can you plz help me with the code for it?
|
|
|
|
|
And once when I find that the result set is empty, I must fill the grid with a custom message.
Can you please help me how.
|
|
|
|
|
dreddy7 wrote: Can you plz help me with the code for it?
No. A little research on your own will be more valuable then giving you the code. I'll give you a hint though. How many rows are there in a DataTable?
only two letters away from being an asset
|
|
|
|
|
I am using a dataset not a data table. So, I am not knowing how to count the rows in a dataset
|
|
|
|
|
dreddy7 wrote: I am using a dataset not a data table.
Stop what you're doing and read the documentations on DataSet before posting again.
only two letters away from being an asset
|
|
|
|
|
Uff......finally....I got it! and thats so simple...I am new to this coding world...so was confused between tables/datasets/adapters and stuff..
Anyways the code is as simple as:
<br />
selectText = "select format from Formats where numberID='" + num + "' and format <> 'Other'"<br />
Dim cmdFormat As SqlDataAdapter = New SqlDataAdapter(selectText, sqlConn1)<br />
<br />
cmdFormat.Fill(dsFormat, "Formats")<br />
<br />
tableFormat = dsFormat.Tables("Formats")<br />
tblFormatsCount = tableFormat.Rows.Count<br />
make the label visible to display the custom text message<br />
lblNoFormat.Visible = True <br />
End If<br />
Session("Formats") = dsFormat<br />
<br />
<br />
dtGrid_Format.DataSource = dsFormat.Tables("Formats")<br />
|
|
|
|
|
Congratulations! Now you have learned something, rather then being told.
only two letters away from being an asset
|
|
|
|
|
Hello,
Thanks for reading this post. Here is my issue. I have a datagrid which 5 bound columns(3 of which are not visible) and 1 button column. Column 1 is date of operation, column 2 is text of email sent by my company etc. My issue is i want to display the entire content of the email text(which can be 2000 characters) inside the cell and have a scroll bar inside the cell, so the page does not become too big. For each row i would like to see the Date, The text of the email and if it exceeds the height of the row, then have a scroll bar within the email text column. How can I do that ?? All help is most appreciated !! This is what i have now.
<asp:DataGrid ID="dgMessages" runat="server" CssClass="table_results" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" Width="80%" GridLines=Horizontal AlternatingItemStyle-BackColor="gainsboro" HeaderStyle-Font-Underline="False"
HeaderStyle-CssClass="table_results_header2" AlternatingItemStyle-CssClass="table_results_altrow" PageSize="5" CellPadding="1" CellSpacing="2" OnPageIndexChanged="dgMessages_PageChanger" OnItemCommand="Button_Click">
<HeaderStyle Font-Bold="True" Wrap="False" CssClass="table_results_header2" Font-Underline="False"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="MESSAGE_DATE" HeaderText="Email Sent" SortExpression="MESSAGE_DATE" >
<ItemStyle Width="10%" />
</asp:BoundColumn>
<asp:BoundColumn DataField="MESSAGE_TEXT" HeaderText="Email Text" SortExpression="MESSAGE_TEXT" >
<ItemStyle Font-Bold="False" Height="10px" Wrap=true Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Left" VerticalAlign="Top" Width="25%" />
<HeaderStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Left" VerticalAlign="Top" />
</asp:BoundColumn>
<asp:BoundColumn DataField="RECORD_ID" Visible=False />
<asp:BoundColumn DataField="PARENT_RECORD_ID" Visible=False />
<asp:BoundColumn DataField="CUSTOMER_ID" Visible=False />
<asp:ButtonColumn ButtonType="PushButton" Text="Reply" />
</Columns>
<PagerStyle Mode="NumericPages" HorizontalAlign=Right></PagerStyle>
<AlternatingItemStyle BackColor="Gainsboro" CssClass="table_results_altrow" />
</asp:DataGrid>
|
|
|
|
|
I think the best you can sensibly do is change the message_text column to a templatecolumn and place a readonly, multiline textbox in there and set it's value to the database field. You will get greyed out scrollbars if the text is short but that can't be helped. You can use css stylesheet to try and make the textbox blend in with the grid background as much as possible.
(I'm not really sure sorting by message_text will produce anything sensible either - you'd be better off leaving that out. Not even sur you can if it corresponds to a text (as opposed to varchar) database field...)
|
|
|
|
|
Thank you...I think that works fine. I created a template column and added a div with overflow property set to auto. That ensured whenever length or width went beyond, it would add scroll bars. works great. Thanks
|
|
|
|
|
I haven't been able to "move" my aspx form into my tab control. I am using master pages with the Ajax tab control on a content page. Has anyone done this or does anyone have a link to some sample code?
|
|
|
|
|
Hi all,
I have a array of treeview, and i want to display that array on GridView that each row of GridView is a treeview.
Ex :
+ John Details
- Age : 12
- Sex : Male
+ Peter Details
- Age : 14
- Sex : Male
+ Jes Details
- Age : 15
- Sex : Female
........
Like display QA in this website.
How could i do that?
-- modified at 11:36 Tuesday 18th September, 2007
|
|
|
|
|
Well - my first suggestion would be to check the title of the forum. It's ASP.NET. You want the Hardware forum.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
As a matter of fact , I am in the form I was intended to be. You see, I was developing an asp.net application which uses a POS terminal for reading magnetic cards and smart cards. I have a vega9000 type POS terminal and I am really stuck.. I was hoping that , any other person who came across with this problem..Maybe some other framework , some other terminal , some other way to sole my problem.. So.. any more suggestions?
Revelation 22:13
|
|
|
|
|
Hi Guys,
I have the sesstion id concatenated to the address line when i load a my
asp.net application pages:
http://Analyzer2/(S21g12siel2gh3o20bhm3dp45)/Menus/ANL_MainMenu.aspx
Does anybody know how to get rid of it?
Cheers.
|
|
|
|