|
I originally posted this in the C# forum but was advised this may be the better place to get the answer.
I have a checkboxlist with different items. I have a comma separated values field that I need to bind to this cbl. The cbl is in a detailsview. I know that I need to loop through the dataset rows so each record in the detailsview is bound with the correct information, however I have only figured out how to bind the first row in the dataset for every record in the detailsview. I know I need to loop through the dataset but am not sure how to do it at the same time as looping through the rows in the detailsview. This below function is called onDataBinding. Can anyone assist?
Thanks in advance!
public void FillControls()
{
int intSN = Convert.ToInt32(Request.QueryString["LookUp"].ToString());
Selections db = new Selections();
DataSet ds = db.Services(intSNo);
int iCount = ds.Tables[0].Rows.Count;
if (iCount != 0)
{
if (dvGetMoreData.CurrentMode != DetailsViewMode.Insert)
{
FillMultipleCheckboxesWithValue((CheckBoxList)dvGetMoreData.FindControl("cblSvcs"), ds.Tables[0].Rows[0]["Services"].ToString());
}
}
}
~Candi
~Candi
|
|
|
|
|
I believe that in FillMultipleCheckboxesWithValue() runs some code for you that will make your problem clearer to me. Can you include this code in your reply?
|
|
|
|
|
Here is the FillMultipleCheckboxeswithValue
public void FillMultipleCheckboxesWithValue(CheckBoxList cbl, string strDBValue)
{
CheckBoxList chkFind = cbl;
string strEval = strDBValue;
if (strEval != " ")
{
string[] arrEval;
arrEval = strEval.Split(',');
int iCount = chkFind.Items.Count;
for (int i = 0; i < iCount; i++)
{
foreach (string str in arrEval)
{
if (chkFind.Items[i].Value.ToString() == str)
chkFind.Items[i].Selected = true;
}
}
}
}
~Candi
|
|
|
|
|
Just exactly what do you mean by "rows of the DetailsView"?? That doesn't make sense in the context of the problem, as each DetailsView should be associated with exactly ONE row (at a time) of the data source.
To review (and make sure we're on the same page) a DetailsView is designed to show one record (the "detail") of a list of records. Most often, the DetailsView is associated with something a like a GridView, so that by selecting one of the records displayed in the GridView you can look at it up close in the DetailsView.
I don't know in what context you're using the DetailsView. Is it standalone, so that you need to hit buttons to move it backward and forward? Is it associated with a GridView?
|
|
|
|
|
I am using the DetailsView as a standalone, yes. But when the checkboxes are populated, each record in the DetailsView displays the same checkboxes selected as the first record. However I have checked the data and the correct data is coming in. So I have narrowed the issue down to the population of the checkboxes. I don't know how to iterate through the records in the DetailsView so that the correct checkboxes are selected for each record.
~Candi
|
|
|
|
|
The answer is simple: your binding function never changes the Row index, so you always fetch data from the same row. You need to change the row to select the record you wish to currently display.
Some control is responsible for accepting the user's choice to change the current record. How does the user select when to move from one record to another? push a button? press Page Down or Down Arrow? I'm assuming it's a button of some sort, and the way to do this is by modifying the Click handler. Can you please attach the Click handler? or explain why that is impossible, if it is impossible? Thanks in advance.
|
|
|
|
|
The user pages to move from one record to another. This is the event that is called when they click to go to the next page of the detailsview.
public void dvGetMoreData_PageIndexChanging(object sender, DetailsViewPageEventArgs e)
{
dvGetMoreData.PageIndex = e.NewPageIndex;
BindData();
}
~Candi
|
|
|
|
|
Perhaps you should change it to this:
public void dvGetMoreData_PageIndexChanging(object sender, DetailsViewPageEventArgs e)
{
dvGetMoreData.PageIndex = e.NewPageIndex;
BindData();
}
public void FillControls()
{
Selections db = new Selections();
DataSet ds = db.Services(intSNo);
int iCount = ds.Tables[0].Rows.Count;
if (iCount != 0)
{
if (dvGetMoreData.CurrentMode != DetailsViewMode.Insert)
{
FillMultipleCheckboxesWithValue((CheckBoxList)dvGetMoreData.FindControl("cblSvcs"),
ds.Tables[0].Rows[dvGetMoreData.PageIndex]["Services"].ToString));
}
}
}
|
|
|
|
|
That works perfectly! However how could this work in a datagrid (I also use it there on another site) since each Page can have multiple records on the same page?
~Candi
|
|
|
|
|
|
Thanks so much for your help! I truly appreciate it.
~Candi
|
|
|
|
|
you're welcome
|
|
|
|
|
Ok I got it! I needed to use the DataGridItem.ItemIndex passed in to the row number of the dataset so the data would populate correctly. THanks for your help with this, cpkilekofp.
~Candi
|
|
|
|
|
Sorry to keep asking this but I let time go by and no one responds.
Now I tried the UPDATE panel for a gridview but it doesn't let you use the select feature within the gridview to select rows (which I need).
Now lets say we have gridview.aspx and add.aspx
on gridview.aspx to add a row they click ADD
so a new window comes up and that is add.aspx.
When they click the submit button (on add.aspx) is there a way to do a GridView.DataBind() from that button to update the gridview on the gridview.aspx page?
|
|
|
|
|
to my knowledge one page does not have access to another page's controls, so you cant bind the grid on your view page from the add page, however i believe it is possible to send messages from the child window to the parent window in javascript, or you can set the parent window to watch for the closed event of the child(assuming you have access to an object that represents the window/page you opened) and use that event to refresh the grid. I fairly certain you can do that in plain ol asp .net 1.1, and would assume it works with ajax if there isnt a better way..you could also hide the grid, show the add controls where the grid was(using seperate asp:panels) then when btnAdd is clicked the add panel goes invisible the grid goes visible, and the databind event is called (i've done that many many times in .net 1.1, and continue to use that method in code i've updated to .net 3.5(yes i know it runs on the 2.0 clr) even though there is probably a better way i have not yet invested the time to find it...i dotn get to set priorities of things i work on..thats the boss's job.
|
|
|
|
|
Thats a good idea I didn't think about.. the hiding and showing... see I have passed strings from one form to another with C# (applications) but not on a web site. I will try the hiding and see if I like. Thank you!
|
|
|
|
|
i used it with normal asp.net 1.1 and 3.5(or 2 whatever) web forms, but i've never tried that inside of an update panel with ajax, assuming thats what you ment by update panel. i dont see why it wouldnt work though. it should actually look pretty neat if it works correctly, if you have any questions feel free to ask i'll help if i can...dont forget to rate answers if they're helpful, provides feedback for people answering and helps people reading determin which posts to take seriously.
|
|
|
|
|
oh, I didn't notice that... but with the Update Panel (Ajax) I set it where it updated like it should.. couldn't even notice it was reloading the gridview or databinding... but the SELECT feature that I added to the GridView (the auto-generated one), it would not select the columns.. Wouldn't call the OnSelectionChange when you selected a row.. which I needed to see what the row was selected... even when it was selected and you tried pulling which row was selected it wouldn't do it.
Well got rid of the update panel, timer, and server manager or whatever and it worked fine with the exact code I had written..
something with it was messing it up
|
|
|
|
|
unfortunatly i havnt gotten into ajax yet and cant help you with that aspect of it, eventually i get to re write our site in ajax, but i have no idea where that hits on the priority list. I have noticed that on new pages i create you have to set the AutoPostBack property to true, to get some events to fire..i tried using a DropDownList's OnSelectedIndexChanged event, and it wouldnt fire without AutoPostBack on, maybe you need to have it on for your grid. you could also use an asp:AsyncPostBackTrigger ControlId="the idof your grid" EventName="your event" which might help...i read about that in an ajax book, but havnt finished it yet. hope it helps.
Alcohol the cause of and solution to all of life's problems.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Hello,
i'm populating a dynamic table in asp.net(c#) i need to invoke a function when double click a row
please if someone could help, or refer me to a good documentation.
thank you in advance adn best regards
|
|
|
|
|
Good luck with that...
I'm pretty sure there is no event in a browser for double click.
I didn't get any requirements for the signature
|
|
|
|
|
|
well if its a javascript function there is a work around.U can use the onclick event, where u can use a global variable,just increment it for the first time and on other click call ur function.
for eg.
var i=0;
function urfn()
{
if(i%2==0)
{
return true
}
else
{
Call_ur_other_fn();
i+=1;
}
}
u can use the same concept with asp.net but i wonn`t recommned it.
When you fail to plan, you are planning to fail.
|
|
|
|
|
thank you for your help, it's working
|
|
|
|
|
Your script will work, but that's a hack...
The bottom line is that whoever is making a requirement or request for a double click in a browser is foolish...
Not only is it a hack to make it work, but it makes for an unintuitive and crappy UI for obvious reasons.
I didn't get any requirements for the signature
|
|
|
|