|
Albert83 wrote: The weird thing DataList1 does show up in the list and I can choose Items property and find control property.
Did you get runtime error or compile time error?
Albert83 wrote: In this code: TextBox PostText=(TextBox)DataList1.Items[IndexHere].FindControl("PostComment");
what's Items[IndexHere] - what index is that. Should I count the number of items in the ItemTemplate?
Yes.you have to do looping through datalist items.
please don't forget to vote on the post that helped you.
|
|
|
|
|
I got the error after I clicked Run, and it says Build failed. I guess it compile erro. What's the difference between run time and compile.
|
|
|
|
|
If we have a checkbox in a grid when we check the the checkbox a javascript function will be called and if we uncheck the same checkbox another javascript will be called.How is it possible...Its Urgent
|
|
|
|
|
|
|
Hey,
try this..
Javascript function
var chkT;<br />
function Test(chkT)<br />
{<br />
alert(chkT.checked);<br />
}
Add template filed. In that add checkbox and then find control in RowDataBound event of Gridview.
Code behind file.
try<br />
{<br />
CheckBox chk = (CheckBox)e.Row.Cells[6].FindControl("chkTest");<br />
chk.Attributes.Add("onclick", "javascript:Test(this);");<br />
}<br />
catch(Exception ex)<br />
{<br />
}
See whats happening...
Thanks,
Sun Rays
To get something you must have to try once.
My Articles
|
|
|
|
|
Thanks for ur kind reply.
I tried like that and i got the click event ,but the pbm is when i uncheck the checkbox i want to call another javascript function.
|
|
|
|
|
Hi,
when you will uncheck you will get item.checked = false.
so you can write if condition.
if(item.checked == true)<br />
{<br />
<br />
}<br />
else<br />
{<br />
}
Hope it will help you
Thanks,
Sun Rays
To get something you must have to try once.
My Articles
|
|
|
|
|
CheckBox ch = (CheckBox)e.Row.Cells[1].FindControl("ChkEdit");
if (ch.Checked == true)
{
ch.Attributes.Add("onclick", "javascript:Del(this);");
}
else
ch.Attributes.Add("onclick", "javascript:BtnAdd_onClick(this);");
I given like that but i wont work
|
|
|
|
|
Hey,
u have mistaken..
Not here..
In Javascript write function...
Call only a single function from codebehind...
But make difference in Javascript...
Got it ?
Thanks,
Sun Rays
To get something you must have to try once.
My Articles
|
|
|
|
|
Is it possible to call 2 javascript function on a checkbox in a grid on onclick event.one is onclick="return Select(this);" .if possible to call another javascript function on the same onclick event..
|
|
|
|
|
Hi
This could help.
<br />
<br />
function select_deselectAll (chkVal, idVal)<br />
{<br />
var frm = document.forms[0];<br />
for (i=0;i< frm.length; i++)<br />
{<br />
if (idVal.indexOf ('CheckAll') != -1)<br />
{<br />
if(chkVal == true)<br />
{<br />
frm.elements[i].checked = true;<br />
}<br />
else<br />
{<br />
frm.elements[i].checked = false;<br />
}<br />
}<br />
else if (idVal.indexOf ('DeleteThis') != -1)<br />
{<br />
if (frm.elements[i].checked == false)<br />
{<br />
frm.elements[1].checked = false;<br />
}<br />
}<br />
}<br />
}<br />
function confirmDelete (frm)<br />
{<br />
for (i=0; i<frm.length; i++)<br="" mode="hold" /> {<br />
if (frm.elements[i].name.indexOf("DeleteThis") !=-1)<br />
{<br />
if(frm.elements[i].checked)<br />
{<br />
return confirm ('Are you sure you want to delete your selection(s)?')<br />
}<br />
}<br />
}<br />
}<br />
<br />
<br />
<asp:datagrid id="MyDataGrid" runat="server" width="700" backcolor="white" bordercolor="black"><br />
CellPadding="3" CellSpacing="0" Font-Size="9pt" AutoGenerateColumns="False" HeaderStyle-BackColor="darkred" HeaderStyle-ForeColor="white"><br />
< Columns><br />
< asp:TemplateColumn><br />
< HeaderTemplate><br />
< asp:CheckBox ID="CheckAll" OnCheckedChanged="javascript: return select_deselectAll (this.checked,this.id);" runat="server" /><br />
< font face="Webdings" color="white" size="4">< /font><br />
< /HeaderTemplate><br />
< ItemTemplate><br />
< asp:CheckBox ID="DeleteThis" OnCheckedChanged="javascript: return select_deselectAll (this.checked, this.id);" runat="server" /><br />
< /ItemTemplate><br />
< /asp:TemplateColumn><br />
< asp:TemplateColumn><br />
< HeaderTemplate><br />
ID<br />
< /HeaderTemplate><br />
< ItemTemplate><br />
< asp:Label ID="StoreID" Text='< %# DataBinder.Eval (Container.DataItem, "ID") %>' runat="server"/><br />
< /ItemTemplate><br />
< /asp:TemplateColumn><br />
< asp:BoundColumn HeaderText="Store" Datafield="Store" runat="server" /><br />
< asp:BoundColumn HeaderText="Address" Datafield="Address" runat="server" /><br />
< asp:BoundColumn HeaderText="City" Datafield="City" runat="server" /><br />
< asp:BoundColumn HeaderText="State" Datafield="State" runat="server" /><br />
< asp:BoundColumn HeaderText="Zip" Datafield="Zip" runat="server" /><br />
< /Columns><br />
< /ASP:DataGrid><br />
<br />
<br />
< asp:Button Text="Delete Items" OnClick="DeleteStore" ID="Confirm" runat="server" /><br />
< span id="OutputMsg" runat="server" /><br />
<br />
public void DeleteStore (Object sender, EventArgs e)<br />
{<br />
string dgIDs = "";<br />
bool BxsChkd = false;<br />
foreach (DataGridItem i in MyDataGrid.Items)<br />
{<br />
CheckBox deleteChkBxItem = (CheckBox) i.FindControl ("DeleteThis");<br />
if (deleteChkBxItem.Checked)<br />
{<br />
BxsChkd = true;<br />
dgIDs += ((Label) i.FindControl ("StoreID")).Text.ToString() + ",";<br />
}<br />
}<br />
string deleteSQL = "DELETE from Stores WHERE stor_id IN (" + dgIDs.Substring (0, dgIDs.LastIndexOf (",")) + ")";<br />
if (BxsChkd == true)<br />
{<br />
try<br />
{<br />
SqlHelper.ExecuteNonQuery (objConnect, CommandType.Text, deleteSQL);<br />
}<br />
catch (SqlException err)<br />
{<br />
}<br />
BindData();<br />
}<br />
}</asp:datagrid>
People Laugh on me Because i am
Different but i Laugh on them
Because they all are same.
|
|
|
|
|
Hi,
I have an appln where in i need to create, text boxes and drop downlists dynamically, the issue here is, how do i retreive the text stored in text box and value selected in the combo.
Thanks in advance
|
|
|
|
|
Just like you normally would. Creating the controls dynamically doesn't change how you access the properties.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
but i am unable to refer to the text property for textboxes,
here is how my code goes, to create control
Dim fldMetadata As TextBox
fldMetadata = New TextBox
fldMetadata.ID = "txtID"
Panel1.Controls.Add(fldMetadata)
I refer to the controls like this,
Dim ctrl As Control
For Each ctrl In Panel1.Controls
If ctrl.ID Like "txtID" Then
'Here i should be able to refer to the control's text property
End If
Next
thanks
|
|
|
|
|
You then should be able to do ctrl.Text=".... "
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Paul Conrad wrote: You then should be able to do ctrl.Text=".... "
a cast is needed I guess
|
|
|
|
|
N a v a n e e t h wrote: a cast is needed I guess
Not really. I just tried it and works fine here.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Paul Conrad wrote: Not really. I just tried it and works fine here.
I think I miss something. But I am unable to get Text property for Control instance as you told.
|
|
|
|
|
I made a mistake by doing a winform and not a webform You can get it in a winform but not webform.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Thanks, I have tried out, but there is no such property
|
|
|
|
|
Anuradha612 wrote: For Each ctrl In Panel1.Controls
If ctrl.ID Like "txtID" Then
'Here i should be able to refer to the control's text property
TextBox txt = (TextBox)ctrl;
Now use txt for getting the textbox properties.
|
|
|
|
|
Anuradha612 wrote: how do i retreive the text stored in text box and value selected in the combo.
Adding to Paul's post, are you getting some problem when retrieving value ? If you are not getting the value entered, check the event where you create dynamic controls. It should be before ASP.NET loads the viestate . Init would be appropriate for dynamic controls.
|
|
|
|
|
Yes, i am unable to retreive the value entered, Pls can you be more clear, with the last post, i am unable to understand,
|
|
|
|
|
This is a viewstate issue. Hope you know about viewstates . It's mechanism used to keep data across postbacks. For solving the problem, override oninit event and add your controls over there. Then ASP.NET will maintain viewstate for the control and you can get it from Controls collection.
|
|
|
|