|
When/where do you run this code? It's before or after the datasource is bound to the control ( or the control hierarchy is built)? Btw, below is a quick example:
<%@ Page Language="C#" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Hashtable datasource = new Hashtable();
datasource.Add("key1", "value1");
datasource.Add("key2", "value2");
datasource.Add("key3", "value3");
datasource.Add("key4", "value4");
datasource.Add("key5", "value5");
Repeater1.DataSource = datasource;
Repeater1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
foreach (RepeaterItem item in Repeater1.Items)
{
CheckBox chkBox = item.FindControl("chkBox") as CheckBox;
if (chkBox != null && chkBox.Checked)
Response.Write("Selected value: " + chkBox.Attributes["value"] + "<br>");
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:CheckBox runat="server" ID="chkBox"
Text='<%# DataBinder.Eval(Container.DataItem, "Value") %>'
Value='<%# DataBinder.Eval(Container.DataItem, "Key") %>' />
<br />
</ItemTemplate>
</asp:Repeater>
<br />
<asp:Button ID="Button1" runat="server" Text="Push Me" On_Click="Button1_Click" />
</div>
</form>
</body>
</html>
|
|
|
|
|
HMMM... I don't know what the deal is but the debugger said the Items were null, but apparently it is working... Kinda...
I have a quick question on state. So I am on my webpage and check a checkbox and then click a button which runs a method in my code behind (so it posts back). I should have access to that checked using the FindControl code above right? Or is the state lost between the postback? Do I have to save the checkbox state somehow and then re set them?
/\ |_ E X E GG
|
|
|
|
|
eggie5 wrote: So I am on my webpage and check a checkbox and then click a button which runs a method in my code behind (so it posts back). I should have access to that checked using the FindControl code above right?
Yes.
eggie5 wrote: Or is the state lost between the postback?
No.
eggie5 wrote: Do I have to save the checkbox state somehow and then re set them?
No. The checkbox control knows how to save its checked status. In fact, the checkbox control updates its checked property at the server side based on it's postback data. If the checkbox is checked, its value is submitted to the server, and the control can gets the value when the post data is loaded (in the LoadPostData method). If the checkbox is not checked, data is not sent to the server, and based on this postback data, the control knows how to set the Checked property accordingly.
|
|
|
|
|
Hi all,
how to assign value to input file type tag.
i.e
i want to assign value to the control. when i give
file.value="india.gif"
it shows a error..
how to solve it. Pls help mee.
thanks
Paul
|
|
|
|
|
Paul,
The value property of the input file[^] element is read-only and does not have the default value, so you cannot set the default value for it.
|
|
|
|
|
Hi Paul,
The value of HTMLInputFile is not settable due to the security reasons. The value property of this control is readonly.
Best Regards,
Apurva Kaushal
|
|
|
|
|
Hi,
I want to update the datagrid control, present in the parent page, from the child page without the page getting fully refreshed. Is there some way with which i can update the datagrid control without full page refresh?
Ashu
|
|
|
|
|
Hi,
You can use frames for that purpose.
Best Regards,
Apurva Kaushal
|
|
|
|
|
Thanks Apurva...but i heard about something called 'scriptcallback'. this technique helps to update a single control on the page without full page reload. I have used 'scriptcallback' but only for html controls and not for asp.net server controls. Any idea?
Ashu
|
|
|
|
|
Hi Ashuu,
Actually i don't have much idea on using scriptcallback for server side controls. But you can also tryout xmlhttp.
http://www.codeproject.com/jscript/refreshpartweb.asp
http://www.15seconds.com/Issue/000612.htm
hope this will be helpful to you.
Best Regards,
Apurva Kaushal
|
|
|
|
|
Thank Apurva,
this link do talk about script callback but nothing is given about asp.net datagrid...its been long time searching for it...anyways.. thanks dear.
Ashu
|
|
|
|
|
Hi
I am using C# and ASP.Net through Visual Studio to develope a Web Application.
I have a DataList that I databind to a DataTable called categoryTable. The categoryTable was loaded from the database and contains a CategoryIndex column and a CategoryName column.
DataList_Categories.DataSource = categoryTable;
DataList_Categories.DataBind();
The DataList contains a LinkButton in each row on which I display the CategoryName:
<ItemTemplate>
<asp:LinkButton CommandName="select" Text='<%# DataBinder.Eval (Container, "DataItem.CategoryName")%>' runat="server">
</asp:LinkButton>
</ItemTemplate>
When I select an item in the DataList I want to get the CategoryIndex from the selected row and load the appropriate products to display them in another DataList. How do I get that information (CategoryIndex) out of the DataListItem?
private void DataList_Categories_ItemCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
{
if (e.CommandName == "select")
{
int index = e.Item.ItemIndex;
DataListItem item = DataList_Categories.Items[index];
}
}
Thanks
Kobus
|
|
|
|
|
Hi Kobus,
Pass that as command argument from the html side and then use it in the code behind side like e.commandargument.
Best Regards,
Apurva Kaushal
|
|
|
|
|
Hi apurva kaushal
Thank you for the reply. On one of the other websites I am still waiting for responses to some of my questions. I shall play a bit with e.commandargument and see what I can come up with.
Kobus
|
|
|
|
|
In the HTML code of the page you can determine the index in the CommandArgument attribute:
<itemtemplate>
<asp:linkbutton commandname="select" commandargument="<%#Container.ItemIndex%>" text="<%# DataBinder.Eval(Container, "DataItem.CategoryName")%>" runat="server">
in the code-behind page:
private void DataList_Categories_ItemCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
{
if (e.CommandName == "select")
{ int index =Convert.ToInt32(e.CommandArgument);
}
}
Then you can send the index value to the other DataList(reload the same page or go to another page that contains the DataList) through a query string :
Response.Redirect("page.aspx?index="+selectedindex);
Then you can get the query string in the page that you were redirected to:
int categoryIndex=Convert.ToInt32(Request.QueryString["index"]);
But i think you should send a CategoryID field value instead of the index that points to the DataGrid item which could be changed.
I am too late but i will never give up
|
|
|
|
|
Hi TheEagle
Thanks for the quick reply, On another website I wait forever and no-one responds to questions. Your HTML code did not come up in the reply. Could you let me have that again please?
Kobus
|
|
|
|
|
Sorry my friend...i forgot to check my reply and i didnt check my email because i was busy...
<ItemTemplate>
<asp:LinkButton CommandName="select" CommandArgument='<%#Container.ItemIndex%>' Text='<%#DataBinder.Eval (Container, "DataItem.CategoryName")%>' runat="server"></asp:LinkButton>
</ItemTemplate>
"I am too late but i will never give up"
|
|
|
|
|
Hi,
I’ve got a problem with my onclick handlers for command buttons
being dropped on page render for a popup window.
On the opening window, I have several command buttons,
and they all have the standard click handler references
(as they should):
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
input type="submit" name="button03" value="submit text"
onclick="WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions( ...
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
... and this isn’t present for command buttons on the popup page.
On the popup window, the standard click handler is not in the button tags
on the rendered page - and the only buttons that have onclick set
are the ones where I use the Attributes property to set the
button for my own JavaScript handlers:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
string fn_call="javascript:doPostBack_JS('Test','','zxc1');"
new_button.Attributes.Add ("onclick", fn_call);
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
... and THAT renders OK:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
input type="submit" name="Button04" value="JavaScript Submit"
onclick="javascript:doPostBack_JS('Test','','zxc1');"
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
I set up a simple test case on the popup window page:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
[script language="C#" runat=server>
void SubmitBtn_Click(Object sender, EventArgs e)
{
Message.Text="Hello World!!";
}
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
[h3>Button Example[/h3>
Click on the submit button.
[asp:Button id="Button1"
Text="Submit"
OnClick="SubmitBtn_Click"
runat="server"/>
[asp:label id="Message" runat="server"/>
[/form>
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
... and this is what got sent to the client:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
[h3>Button Example [/h3>
Click on the submit button.
[input type="submit" name="Button1" value="Submit" id="Button1" />
[span id="Message"> [/span>
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
As should be obvious, onclick isn’t set on the rendered page.
The script source tags are present on BOTH the primary page,
AND the popup page:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
[script src="/Webfolder01/WebResource.axd?d=
[script src="/Webfolder01/WebResource.axd?d=
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
This is the JavaScript function that opens the popup window:
// =======================================================
function popup01 ()
{
var win_url
= "http://localhost/Webfolder01/CtrlInit12b.aspx";
var win_name
= "_blank";
var win_chrome
= "toolbar=0,scrollbars=1,location=1,statusbar=0,menubar=0,resizable=1";
var win_dimn
= ",width=444,height=444,left = 290,top = 162";
DBname_popup = window.open (win_url, win_name, win_chrome + win_dimn);
if (window.focus) {DBname_popup.focus()}
stop_postback = true;
}
// =======================================================
The really freaky thing about this is that it was working last week,
after I tested it - and it WAS working OK.
Does anyone have any idea as to why this is happening?
THANK YOU FOR YOUR ATTENTION TO THIS!!!
.
wylbur
-=-=-=-=-=-=-=-
|
|
|
|
|
Hi,
So I have this problem, here it is.
I have a repeater with a check box in each itemtemplate. What I need is, to find all checked checkboxes (in the repeater) and send their respective "ID" properties back to the Invite(string ID) method on the server (my aspx.cs file).
Does anybody know how to do this ? I was trying to do it with javascript but I'm not good enough. I guess if somebody could just show me how, using javascript, to find all the seleted checkboxes in my repeater and getting their ID properties, (i.e. <%# DataBinder.Eval(Container.DataItem, "ID") %> ), then I think i know how to post it back to the server us javascript.
Thanks.
/\ |_ E X E GG
-- modified at 0:43 Monday 15th May, 2006
|
|
|
|
|
Alex,
The way to access the checkbox with javascript in the repeater is similar to that in the datagrid control, you can see the site[^] for the sample script.
However, IMO you may not need to use javascript to access the checkbox in the RepeaterItem to get the id values, instead you can walk through the Repeater.Items[^] collection, and get reference to the checkbox control, you then can check if the checkbox is selected or not, and get the id value bound to it. And I think you may want to collect the ids of the checked checkboxes with javascript when you intend to use AJAX to do something.
|
|
|
|
|
HAHA,
I just discovered the Items property. This looks good !
/\ |_ E X E GG
|
|
|
|
|
so If I binded a class AdminPaper to the Repeater, I should be able to cast Items[i] in to an AdminPaper right?
/\ |_ E X E GG
|
|
|
|
|
|
Hi All,
I have no idea how to save files on client machine in ASP.NET. I tried with Request.Response(), but i failed to do that. Can anyone provide me the solution.
I am trying to save a .xml file in C:\TEMP of the client machine
Regards
Suma B R
|
|
|
|
|
using System.Net;
WebClient client=new WebClient();
client.DownloadFile("url path of the file on the server","Localfilename");
Please..may you tell me why do you want to download .xml file on the client machine?
"I am too late but i will never give up"
|
|
|
|