|
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
|
|
|
|
|
|
|
Thanks for replying. I used that too but it has same problem. Please help me.
DAsh04
|
|
|
|
|
I would try this
protected void CheckLogin()
{
if (Session["LoginAdminUser"] == null)
{
Response.Redirect("~/admin/oola_log_in.aspx");
}
else
{
LoginUser= Session["oLoginAdminUser"].ToString(); }
}
LoginUser = Type String
Session["oLoginAdminUser"] = Type Object so you need the ToString() addition
|
|
|
|
|
no not solved still
DAsh04
|
|
|
|
|
i want to use this code in asp
VBA.Calendar = vbCalHijri
date
|
|
|
|
|
Hello everybody,
I am facing a problem. I am trying to upload a file using Pure ASP and I am not using any component. On development server it is allowing upto 10MB to upload but on production server it is not taking more than 1KB. If I try to upload more than 1KB file "Internal Server Error" page is getting displayed.
Thanks
Intelligence is measured by common sense not by how many scholarly books you read.
|
|
|
|
|
Hi,
In web.config <system.web>, add the following code
<system.web>
<httpruntime maxrequestlength="1024000" />
//Here u can give ur maximum size of the file.
</system.web>
Sutheesh Ramachandran
Cybernet Software Systems,
T Nagar, Chennai 17.
|
|
|
|
|
Thanks for the reply but it is not ASP.NET application rather it is Pure/Classic ASP application.
Intelligence is measured by common sense not by how many scholarly books you read.
|
|
|
|
|
This is an asp.net forum, So you could ask better your question in an asp forum
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
|
|
|
|
|
Hi
I have gridview with a values in as well as a dropdownlist
When I click on the dropdownlist to choose a value I need this value to then be updated to the database.
My question is how can I find the id of the current row I am on so that the correct record is updated?
any help on this would be great thanks!
|
|
|
|
|
.netman wrote: I have gridview with a values in as well as a dropdownlist
When I click on the dropdownlist to choose a value I need this value to then be updated to the database.
My question is how can I find the id of the current row I am on so that the correct record is updated?
any help on this would be great thanks!
Do you want to update all gridview data on button click event?
or
Do you want to update only one row on Droddown selected index change event?
regard
khan
please don't forget to vote on the post that helped you.
|
|
|
|
|
I just need to update the row that I am currently on.
I want to update just the value I have chosen from the dropdownlist but I need to match it to the correct ID for that row. hope that makes sense
Also how can I find the dropdownlist for the current row.
I have:
DropDownList dd = ((DropDownList)row2.FindControl("ddorder")); but its showing object reference error
That code above is on my selectecchange event for the dropdownlist
thanks so far!!!
|
|
|
|
|
.netman wrote: I want to update just the value I have chosen from the dropdownlist but I need to match it to the correct ID for that row.
If you want to update single row on dopdown selected index change event then first find out dropdownlist on rowCreatedEvent of gridview and create event handler of selected index changed.
.netman wrote: DropDownList dd = ((DropDownList)row2.FindControl("ddorder"));
Look at here
On rowCreatedEvent of Gridview
if(e.Row.Rowtype==DataControlRowType.DataRow)
{
DropDownList ddl=(DropDownList)e.Row.FindControl("DropDownListID")
ddl.ToolTip=CurrentID;
}
On SelectedIndexChangeEvent,You have two argument e as eventArgs and Sender as an object
cast object to dropdownlist and get selectedValue and update data
for Example
DropDownList ddl=(DropDownList)sender;
string selectedValue=ddl.SelectedValue;
string ID=ddl.ToolTip;
regard
kHan
please don't forget to vote on the post that helped you.
|
|
|
|