|
i have this code, when i run this page, this reader dont bring the first record. i ran this sql(SELECT) on the sql database and runs fine, and if i put the seme SELECT in a Sqldatasource and bind the griview, it works fine too. what is wrong with this reader?
******************
any idea.
THIS WORKS
SqlDataSource1.SelectCommand = "SELECT products.pid, products.pname, flavors.fl_name, product_flavors.flavor_icon FROM product_flavors LEFT JOIN flavors ON product_flavors.flavorsid = flavors.flavorsid LEFT JOIN products ON product_flavors.pid=products.pid WHERE products.pid = 84"
ProductListView.DataSource = SqlDataSource1
ProductListView.DataBind()
**********************
THIS NOT BRING ALL THE RECORDS. ALWAYS LEAVE ONE OUT.I THINK THE FIRST ONE.
Dim conn As SqlConnection
Dim cmd As SqlCommand
Dim cmdString As String = "SELECT products.pid, products.pname, flavors.fl_name, product_flavors.flavor_icon FROM product_flavors LEFT JOIN flavors ON product_flavors.flavorsid = flavors.flavorsid LEFT JOIN products ON product_flavors.pid=products.pid WHERE products.pid = 84"
conn = New SqlConnection(ConfigurationManager.ConnectionStrings("eConnectionString").ToString)
cmd = New SqlCommand(cmdString, conn)
conn.Open()
Dim myReader As SqlDataReader
myReader = cmd.ExecuteReader()
myReader.Read()
GridView1.DataSource = myReader
GridView1.DataBind()
conn.Close()
|
|
|
|
|
orsini wrote: myReader.Read()
I think the above line is the problem
When you Use Read reader move to next record.
Instead of binding the reader try to bind DataTable.
orsini wrote: cmd = New SqlCommand(cmdString, conn)
conn.Open()
Dim myReader As SqlDataReader
myReader = cmd.ExecuteReader()
myReader.Read()
GridView1.DataSource = myReader
<br />
Dim adp as new SqlDataAdpter(cmdString,conn);<br />
Dim dt as new DataTable<br />
adp.Fill(dt);<br />
GridView1.DataSource = dt<br />
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
|
|
|
|
|
bah - your answer wasn't there when I started writing mine!
|
|
|
|
|
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
|
|
|
|
|
Try removing the line
myReader.Read()
before binding it to the GridView
The DatReader is a forward-only cursor and you have moved it one record on by reading from it.
You might want to check that ANY rows are returned first though - use
If myReader.HasRows Then....
|
|
|
|
|
thank you so much, both answer are great, both worked fine, thanks again.
I am trying to get away from those fance interface user and get more into the code behind.
so, when I bind that productlistview. with the reader, i have a funcion that return the selected value.
Public ReadOnly Property prodid() As String
Get
Return ProductListView.SelectedValue
End Get
End Property
which i retrieve it in the next page. how can i tell the productlistview, that the datakeynames = myrreader("pid")
from the code behind.
thanks for your help.
|
|
|
|
|
I need to use asp.net to access and capture video from webcam but i want to make it browser independent and OS independent on client side.
I have seen in many articles calling avicap32.dll and also if I use DirectShow API of .net, will it be OS independent?
Or there any other solutions for the problem??
Shall be grateful if you help.
|
|
|
|
|
My application is in Asp.net 2.0.
In my applicaton,
There is one Repeater contorl.
in Repeater there is a button.
I have to disable that button with javascript.
can any one help me.
how can i find bytton id in javascript.
thanks
|
|
|
|
|
When you want to disable?Or In which event?
You need to pass the button id MyButton.ClientID to the JS Function.
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
|
|
|
|
|
Thanks for replying me.
I want to disable it on form button click event.
thanks
|
|
|
|
|
In page load add
button1.Attributes.Add("onclick","javascript:DisButton('" & button2.ClientID & "')")
JS Function
function DisButton(cntrl)
{
document.getElementById(cntrl).disabled=true;
return false;
}
on button1 click button2 will disable.
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
|
|
|
|
|
thanks for Reply.
but i have to access control id from javascript.
like we access another control value.
also button on which i have to access javascript is outside the repeater.
and i required control id which is in repeater.
can u help me in this regards
thanks
|
|
|
|
|
I'm not sure what you are trying to do.
You have repeater and that contains a button atleast. say button1
You have an another button thats outside the repeater. say button2
So on button2 click you want to disable the button1.
If this is the requirement....
1.You can use the FindControl function of repeater to get controls inside therepeater, and pass the ID of button1 to the JS function.
2.You can store the ID inside a hidden field and get it in the JS.
Hop this Helps you...
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
|
|
|
|
|
Hi
I have the following code which should count the number of rows in the gridview ands then I want it to assign a number to it, so if there three rows it would assing 1, 2, 3 to each row but its not working it shows error Cannot implicitly convert type 'int' to 'string'
any help would be great!
for (int x = 0; x < GridView1.Rows.Count; x++)
{
GridViewRow row = GridView1.Rows[x];
dropdown = ((DropDownList)row.FindControl("ddorder"));
int count =+ 1;
dropdown.DataValueField = count;
}
|
|
|
|
|
Your Code
for (int x = 0; x < GridView1.Rows.Count; x++)
{
GridViewRow row = GridView1.Rows[x];
dropdown = ((DropDownList)row.FindControl("ddorder"));
int count =+ 1;
dropdown.DataValueField = count;
}
Tip:
Or the control does not exist
or it should be count.ToString();
Int32 count = 0;
DropDownList dropdown = new DropDownList();
foreach (GridViewRow row in GridView1.Rows)
{
try
{
dropdown = ((DropDownList)row.FindControl("ddorder"));
count++;
dropdown.DataValueField = count.ToString();
}
catch (Exception err)
{
}
}
Good Luck
|
|
|
|
|
I tried your code and it showed blank in the dropdownlist:
why would this be?
thhanks"
|
|
|
|
|
You only fill DataValueField but you should also fill DataTextField.
In the OnSelectedIndexChanged- event you can then pick the .SelectedValue, which is the DataValueField.. If you pick in that event the .SelectedIndex.Text you have the DataTextField.
In this case you can show a database description field in the DataTextField while attaching it's databse field ID to the DataValueField.
|
|
|
|
|
OK thanks for that
Now say Ive got 3 rows I want to add 1,2,3 to each dropdown in each row therefore I want the number of rows to appear in the dropdownlist, how would I do that? WOuld it just be an extension to the code I have?
|
|
|
|
|
the extension would be like this.
DropDownList dropdown = new DropDownList();
foreach (GridViewRow row in GridView1.Rows)
{
try
{
dropdown = ((DropDownList)row.FindControl("ddorder"));
for (int count = 1; count <= 3; count++)
{
dropdown.Items.Add(new ListItem(count.ToString(),count.ToString()));
}
}
catch (Exception err)
{
}
}
|
|
|
|
|
OK, final question
How do I select the correct row dropdownlist when updating my database.
At the moment when I set it to dropdown.selecteditemvalue it takes the very last row value instead of the current one.
How would I fix this?
thanks for your great help so far!
also how do I get another column value from the same row?
|
|
|
|
|
DropDown.SelectedValue I guess you mean
You know you hav to run along each GridViewRow to see the value of the dropdown control?
Like i showed you
Int32 selectRow = 0;
foreach (GridViewRow row in GridView1.Rows)
{
GridView1.SelectedIndex = selectRow;
// find you dropdownControl
//row.SelectedValue will show now values
selectRow++;
}
|
|
|
|
|
digimanus wrote: dropdown.Items.Add(new ListItem(count.ToString(),count.ToString()));
There is no reason to set the text and the value to the same value. A ListItem without a value returns the text property as value.
dropdown.Items.Add(new ListItem(count.ToString()));
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
I did not know this. Thanks for the tip
|
|
|
|
|
Well....If you want to add an item to the DropDownList you could do
dropdown.Items.Add(new ListItem(count.ToString(),count.ToString()));
in stead of dropdown.DataValueField = count.ToString();
dropdown.DataTextField = count.ToString();
DataxxxxField is used for DataBinding for values retrieved from a database
In page_Load remember to place code in
if (!Page.IsPostBack)
{
// the code
}
modified on Thursday, July 10, 2008 9:37 AM
|
|
|
|
|