|
thnx but how can I do that, I wrote something like that but I can't seem to link it with the datagrid.
TemplateColumn tc = new TemplateColumn();
tc.HeaderText = "Display on Map";
LinkButton LinkButton2 = new LinkButton();
LinkButton2.CommandName = "btnShow2";
I don't know the exact code for it, coz I've always use the wizard from the design.
|
|
|
|
|
First you need to create the template column and then in the itemdatabound event create the control which you want to be there in the template column. Also put templatecreation code after the bound column creation code.
Best Regards,
Apurva Kaushal
|
|
|
|
|
Do u have any Link for an example that I can use as a reference??
|
|
|
|
|
I don't know about the link but you can search through google.
BTW here is the code to create bound column and template column dynamically:
BoundColumn bCol = new BoundColumn();<br />
bCol.DataField = DC.ColumnName;<br />
bCol.HeaderText = DC.ColumnName;
here DC is the datacolumn.
TemplateColumn tColStatus = new TemplateColumn();
tColStatus.HeaderText = "Status";
only thing is after creating these columns you need to add them to the datagrid and once it is done in the itemdatabound event you can place the following code to add the control to the template column.
<br />
Label lblStatus = new Label();<br />
lblStatus.EnableViewState = true;<br />
lblStatus.ID = "lblStatus";<br />
lblStatus.Text = "Pending";<br />
e.Item.Cells[index of the template column].Controls.Add(lblStatus);
Best Regards,
Apurva Kaushal
|
|
|
|
|
thnx for the code, really helpful but there's still one problem, when I insert the linkButton using this code:
e.Item.Cells[1].Controls.Add(LinkButton2);
The header of the template column becomes the control itself, I mean the header becomes a LinkButton too, so why does that happen..and how can I resolve this issue??
thnx in advance for all ur help
|
|
|
|
|
That is OK what you need to do is to put the code of itemdatabound event inside this "if" loop:
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
Best Regards,
Apurva Kaushal
|
|
|
|
|
thnx a loooot
sorry for bothering u but the linkbutton doesn't execute the ItemCommand event. I wrote:
LinkButton2.CommandName = "lnkShow";
and then inside the DataGrid_ItemCommand event I wrote some code that executes something in the web application, but when I press the LinkButton, nothing is executed and the new column actually disappears from the datagrid..Am I missing something in the code??
sorry again and thnx in advance for all ur help
|
|
|
|
|
Nada Adel wrote: DataGrid_ItemCommand event I wrote some code that executes something in the web application
this has to get executed. Have you mention about the item command event in the datagrid.
Nada Adel wrote: new column actually disappears from the datagrid
This is happening because you are not binding the datagrid again after the itemcommand event. You need to bind the grid in the itemcommand also.
Best Regards,
Apurva Kaushal
|
|
|
|
|
thnx for the quick reply
I've mentioned the Item_Command event of the datagrid:
public void DataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.DataBind();
Response.Write("Nada"); //does not appear
if (e.CommandName == "lnkShow2")
{
//Some code
}
}
when I press the linkbutton in the template column, the item_command event. He never enters it in the first place. It is never executed.
Did I miss the definition of the Item_Command event, I mean it was working when I designed the Template Column at design time. Is there something missing. Here's my code:
TemplateColumn tColStatus = new TemplateColumn();
tColStatus.HeaderText = "Status";
DataGrid1.Columns.Add(tColStatus);
// Creating the Control
protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
LinkButton LinkButton2 = new LinkButton();
LinkButton2.EnableViewState = true;
LinkButton2.ID = "lnkShow";
LinkButton2.Text = "Show";
LinkButton2.CommandName = "lnkShow2";
e.Item.Cells[1].Controls.Add(LinkButton2);
}
}
Please check it and let me know if I missed something. I really want it work. I appreciate all ur help
|
|
|
|
|
You need to attach the event to the datagrid. Something like this:
DataGrid1.ItemCommand +=new DataGridCommandEventHandler(this.DataGrid1_ItemCommand);
Best Regards,
Apurva Kaushal
|
|
|
|
|
still, not executed?? where exactly shall I put it??
|
|
|
|
|
Just after the datagrid binding and creating columns code.
Best Regards,
Apurva Kaushal
|
|
|
|
|
Still not working, sorry.. I give up, the DataGrid_ItemCommand is not invoked at all?
I don't know what to do.
|
|
|
|
|
I don't find any reason for it not functioning. You debug it properly and then can see what exactly is the problem. Because I have implemented the same thing and it is working absolutely fine for me.
Best Regards,
Apurva Kaushal
|
|
|
|
|
Thnx a loot, well I did in a different way using TemplateColumns at design time and I bound them to certain fields in the database using DataBinder.Eval.. pretty neat and the LinkButton is shown as the last column successfully.
Anyaways..thnx a lot, just bothering urselft to answer questions is a big thing for me..
|
|
|
|
|
Always welcome..
Its really nice that finally you got the things working (By whatever way )
Best Regards,
Apurva Kaushal
|
|
|
|
|
Hi all,
I want to compare my system time with the time in MS Access table. I want to display those records which are greater than the current time(even the seconds not the milli seconds).
Plz any one suggest me the query.
Thanks in advance
bye
Know is Drop, Unknown is Ocean
|
|
|
|
|
Hi,
I hope you can use CompareTo() method available in DateTime class. Basically you need to provide your current that will be available in your system. You can get it through using DateTime.Now
Then get the Datetime from access table and use the CompareTo method to findout the difference.
Hope this will help
Rakheesh
|
|
|
|
|
Happy mondays everyone,
I'm trying to get an ASP page to use a master page. I've got the HTML / ASP side of things working and my page looks like it should but I'm having problems getting my scripts to work. ASP doesnt't seem to like me putting a contentplaceholder in the document head so i can't add a tag. I've tried to use Page.Header and inject a tag that way but i can't seem to get that to work and it seems somewhat untidy.
What's the best way of getting this stuff to work?
Thanks
Russell
|
|
|
|
|
It seems that while Visual studio was telling me that the tag name is unrecognised it was making me look in the wrong place, my error was elsewhere and it turns out that visual studio was just incorrectly reporting an error.
I now have a problem that my control names have changed.
How do you build your javascript when the control names change when the controls are moved to placeholders? I had the same problem with wrapping code in webcontrols and ended up hard coding the control name in the javascript which was something i planned to come back to fix.
Thanks
Russell
|
|
|
|
|
I've written a function renderClientObjects, which hooks in and emits a js var, linked up with document.getElementById coded on the server side so I can use ClientId - can show you if needed - works nicely...
"Now I guess I'll sit back and watch people misinterpret what I just said......"
Christian Graus At The Soapbox
|
|
|
|
|
How to create a pop-up window?
|
|
|
|
|
Use the following JS
<br />
window.open("MyPopUp.aspx","","scrollbars=yes,menubar=no,status=no,left=0px,top=0px,resizable=yes, width=350px, height=300px");<br />
Mubashir
Software Architect
Storan Technologies Inc, USA
Every job is a self portrait of the person who did it.
|
|
|
|
|
I am trying to connect to the database using SQL SErver 2005. I am creating a web application in VB.NET 2005.
I have defined a Connections string in Web.Config and now acessing the string to connect to the database. But It gives me this error.
"Cannot open database "Ranking" requested by the login. The login failed. Login failed for user 'FAISAL\ASPNET'."
I am using Windows connection in connecting SQL SErver Express Editiion 2005.
Please help me guys its very urgent.
KHATRI
|
|
|
|
|
KHATRI,
You need to read This[^]
Mubashir
Software Architect
Storan Technologies Inc, USA
Every job is a self portrait of the person who did it.
|
|
|
|