|
|
Thanks man, I tried to work through you article but
they are working on a gridview and it's not quiet the
same with a datagrid, for instance this line:
chkBoxIndex = (string)grdView.DataKeys[row.RowIndex].Value.ToString();
in a datagrid there is no [row.RowIndex]
and this is what is used to add all the row indexs to the arraylist.
do know anything relating to a datagrid in particular?
I appreciate your help man
|
|
|
|
|
The code seems ok to me, what problem are you facing?
Are you getting any error?
|
|
|
|
|
Hi friend,
No the code does not give any trouble, just now I tried this:
foreach (DataGridItem item in contacts.Items)
{
chkSelection = (CheckBox)item.FindControl("chkSelection");
if (chkSelection.Checked)
{
string contact = contacts.Items[0].Cells[4].Text;
errors.Text = contact.ToString();
errors.Visible = true;
}
}
But I want to get all phone numbers if checked, so i tried to replace:
Items[0].Cells[4] with
Items[item].Cells[4] and
it gives an error it can't convert
Items[item] to Items[int]
do you know I can manager to get all the phone numbers...
please help if you can
|
|
|
|
|
Hey u can again use the Findcontrol method in order to retrieve contact no
foreach (DataGridItem item in contacts.Items)
{
int i=0;
chkSelection = (CheckBox)item.FindControl("chkSelection");
if (chkSelection.Checked)
{
string contact = Convert.ChangeType((Label)item.FindControl("lblContactNo"),Label).text;
string[] arr=new string[20];
arr[i]= contact;
i++;
}
}
I hope this will help u....
|
|
|
|
|
This will work, but you have to add a label control for your Contact No column.
I think there should be something like (item.Index) which you can use as items[item.Index].
I am not sure but there has to be something which'll give you the rowindex.
|
|
|
|
|
<blockquote class="FQ"><div class="FQA">MorgSim wrote:</div>foreach (DataGridItem item in contacts.Items){ chkSelection = (CheckBox)item.FindControl("chkSelection"); if (chkSelection.Checked) { string contact = contacts.Items[0].Cells[4].Text;//this retrieves the phone_num at Items[0].Cells[4] errors.Text = contact.ToString();//whether checked or not, not what iam expecting really. errors.Visible = true; }}</blockquote>
Here you are not using "item" anywhere.
So, better option would be to use for loop instead of foreach.
<pre>
for(int i=0;i<contacts.Items.Count;i++)
{
string contacts = contacts.Items[i].Cells[4].Text;
}
</pre>
I think this should work.
|
|
|
|
|
Hey thanks for your help...
when I do exactly like you code it works ok as it will get all the phone numbers.
But remember i only want those phone numbers where checked is true..
So i modified the code like this:
for (int i = 0; i < contacts.Items.Count; i++)
{
foreach (DataGridItem item in contacts.Items)
{
chkSelection = (CheckBox)item.FindControl("chkSelection");
if (chkSelection.Checked)
{
string cont = contacts.Items[i].Cells[4].Text;
errors.Text += cont;
errors.Visible = true;
}
else
{
errors.Text = "";
errors.Visible = true;
}
}
}
here only the last row results to true when checked
I don't know why other rows are skipped even when checked.
Can you spot anything here?
|
|
|
|
|
Good, atleast you got a headstart.
Now, i want to know, what is this errors.Text ?
and why you are doing error.Text="" ?
I think because of this it is giving problem, try removing error.Text="".
|
|
|
|
|
nagendrathecoder wrote: Now, i want to know, what is this errors.Text ?
This will just show me the numbers that have been selected, its a label..
nagendrathecoder wrote: and why you are doing error.Text="" ?
I have disabled this and,
When I check any row, all the phone numbers are retrieved instead of just one that is checked
I don't know why this is behaving this way..
|
|
|
|
|
IMO, you don't need that foreach loop.
Remove that loop, cast checkbox like this:
CheckBox chk = (CheckBox)contacts.Items[i].Cells[4].Text;
Now, see whether it is checked or not and then append it to errors.Text.
Don't include errors.Text="".
|
|
|
|
|
nagendrathecoder wrote: CheckBox chk = (CheckBox)contacts.Items[i].Cells[4].Text;
Thanks man, well
When I do that I get an error:
Cannot convert type 'string' to 'System.Web.UI.WebControls.CheckBox'
|
|
|
|
|
Yes.
You have to do :
CheckBox chk = (CheckBox)contacts.Items[i].Cells[4].FindControl("chkBox");
|
|
|
|
|
hey hey hey brother!
man you are such a star*****
Finally all is working like expected...thanks alot
for being so helpful man
wish I could send you this
thanks again...cheers
|
|
|
|
|
Glad to know that its working. Always welcome.
|
|
|
|
|
Dear All,
I have following code in PageLoad Event
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
Session["FilteredTable"] = string.Empty;
if (Page.IsPostBack)
{
try
{
bindSelectedFields();
bindReport();
}
catch (Exception ex)
{
Response.Write(ex.Message + "<br>"+ ex.StackTrace);
}
}
}
and the same I have Code in design time
<table id="tFilterButton" ><%Response.Write(hidRmvFilter.Value);%></table>
which hidRmvFilter is hidden field.
the thing is I want to empty session variable at first visit of page. but in above code I dont know what is wrong which the session gets empty at any postback. I debugged the code and checked that when it reaches
<table id="tFilterButton" ><%Response.Write(hidRmvFilter.Value);%></table>
it again goes to the first IF block (I).
any ideas why the session gets empty at each postback or I am looking to an alternative to store session variable at any postback which it should get empty only in first page visit?
Abdul Rahaman Hamidy
Database Developer
Kabul, Afghanistan
|
|
|
|
|
I think the problem is in your functions
Abdul Rahman Hamidy wrote: bindSelectedFields();
bindReport();
May be the functions causing postback again.
Try to check it again.
|
|
|
|
|
Provided your bindSelectedFields() and bindReport() are correct, this should work.
But only if you're actually performing a Postback (clicked button or similar). It won't work on a first visit per session basis if your requesting the page via a GET (such as clicking a link, or navigating directly to the page in the address bar.
|
|
|
|
|
thanks for reply, Would you please give me more information bz yours is not so clear for me.
Abdul Rahaman Hamidy
Database Developer
Kabul, Afghanistan
|
|
|
|
|
hi,
i have developed a simple form which have only one button and when user click on button then just server datetime will be shown by
icallback. few days back it was working but now i saw it is stop working. i am running the program from VS2005 IDE. i just can not understand
why it is not working. i am getting two error and
the errors are 1) WebForm_DoCallback is not defined
2) WebForm_InitCallback is not defined
please help me how to fix this error.
here i am giving my code
html
-----
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="BasicCallBack.aspx.cs" Inherits="BasicCallBack" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script language=javascript>
function GetOutputFromServer(strOutput)
{
alert(strOutput);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnVal" runat="server" OnClientClick="CallServerMethod('1','2');return false;"
Style="left: 455px; position: relative; top: 204px" Text="Get Server Date" /></div>
</form>
</body>
</html>
codebehind
-------------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class BasicCallBack : System.Web.UI.Page, ICallbackEventHandler
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsCallback)
{
ClientScriptManager csm = Page.ClientScript;
String callbackRef = csm.GetCallbackEventReference(this, "arg", "GetOutputFromServer", "");
String callbackScript = "function CallServerMethod(arg, context) {" + callbackRef + "; }";
csm.RegisterClientScriptBlock(this.GetType(), "CallServerMethod", callbackScript, true);
}
}
public void RaiseCallbackEvent(String clientArgs)
{
}
public string GetCallbackResult()
{
return DateTime.Now.ToLongDateString();
}
}
please help me to fix this error.
tbhattacharjee
|
|
|
|
|
Tridip Bhattacharjee wrote: few days back it was working but now i saw it is stop working.
The code you have presented works for me,
(visual studio 2008) I suspect something
on your machine was changed , I couldn't
guess what ?
Try to do a "Restore" back to when it was
working for you.
|
|
|
|
|
How are you running it? Are you using the developer web server or IIS? If you are using IIS then you should reinstall the framework for the site using the regiis command. For exact syntax check google.
|
|
|
|
|
i am using the developer web server means i run the code from VS2005 IDE. i am not using IIS.
tbhattacharjee
|
|
|
|
|
I have a User Control that has a custom property, which I want to set by a theme.
The custom property is used in javascript that is injected into the page by a
Page.ClientScript.RegisterStartupScript method in Page_Load.
Basically I do the following :
- Placed a [Themeable(true)] attribute above my user control class.
- I register my user control in web.config.
<pages styleSheetTheme="Sunset">
<controls>
<add tagPrefix="UC" src="~/UserControls/MyUserControl.ascx" tagName="MyUserControl"/>
</controls>
</pages>
- Placed a skin file under Sunset directory in App_Themes with content :
<UC:MyUserControl runat="server" CustomColor="#FF0000" />
At runtime everything works fine, but in the designer I keep getting the error :
Error Rendering Control
An unhandled exception has occured.
There was an error parsing the theme: The control type "System.Web.UI.UserControl" cannot be themed.
What am I missing here ?
tia
|
|
|
|
|
I'm having the same problem and haven't got any clue yet.
|
|
|
|