DataGrid cell click event #2

Hi,

I have two problems with datagrid. These are -

1. I am fetching data from database and getting it in a dataset. In the time of display in a datagrid I want to display each row of dataset as a column in the datagrid. How can I do so?

2. In the datagrid, I want to write a click event on every cell click. In that click event I need to know exactly which cell was clicked (may be with row and column number).

Please help me. Thanks in advance.

Angshujit

0
angshujit
11/6/2008 10:14:29 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

3 Replies
376 Views

Similar Articles

[PageSpeed] 9

 create a separate table with the rows which yiu have as columns and bind the rows using for loop.


Cheers,
Achutha Krishnan

~ No one can do everything, but everyone can do something ~
0
engineerachu
11/7/2008 6:18:28 PM

 

angshujit:
I am fetching data from database and getting it in a dataset. In the time of display in a datagrid I want to display each row of dataset as a column in the datagrid. How can I do so?

create a separate table with the rows which yiu have as columns and bind the rows using for loop. 


Cheers,
Achutha Krishnan

~ No one can do everything, but everyone can do something ~
0
engineerachu
11/7/2008 6:18:53 PM

Hi angshujit ,

angshujit:
1. I am fetching data from database and getting it in a dataset. In the time of display in a datagrid I want to display each row of dataset as a column in the datagrid. How can I do so?

Please check these two links :

sqlserver 2005 :
c# code:
 
 
angshujit:
2. In the datagrid, I want to write a click event on every cell click. In that click event I need to know exactly which cell was clicked (may be with row and column number).
 

Then , you need to add javascript to cell manually.

    protected void Page_Load(object sender, EventArgs e)
    {
       //string date = "16:00:00";
        TimeSpan spen = new TimeSpan(16, 00, 00);
        DateTime mydt = new DateTime(spen.Ticks);
        string test = mydt.ToShortTimeString();


        if (!IsPostBack)
        {

            DataTable table = new DataTable();
            table.Columns.Add("test");
            DataRow dr = table.NewRow();
            dr["test"] = "1";
            table.Rows.Add(dr);
            this.dg.DataSource = table;
            dg.DataBind();
        }

    }














    protected void dg_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        LinkButton sel = e.Item.FindControl("se") as LinkButton;
        if(sel!=null)
        {
            DataRowView drv = e.Item.DataItem as DataRowView;
           string test = this.ClientScript.GetPostBackClientHyperlink(sel,"");

           e.Item.Cells[1].Attributes.Add("onclick", "document.getElementById('HiddenField1').value = " + drv["test"].ToString () + " ; " +  test);
        }

    }
    protected void dg_SelectedIndexChanged(object sender, EventArgs e)
    {
        
    }
    protected void dg_ItemCommand(object source, DataGridCommandEventArgs e)
    {
        string result = this.HiddenField1.Value; ;


    }
 

 

 <asp:DataGrid runat="server" ID="dg" OnItemDataBound="dg_ItemDataBound" Width="321px" OnItemCommand="dg_ItemCommand" OnSelectedIndexChanged="dg_SelectedIndexChanged" >
     <Columns>
         <asp:TemplateColumn>
             <ItemTemplate>
                 <asp:LinkButton ID="se" runat="server" CausesValidation="false" CommandName="Select" Text="Select"></asp:LinkButton>
             </ItemTemplate>
         </asp:TemplateColumn>
     </Columns>
 </asp:DataGrid>
     <asp:HiddenField ID="HiddenField1" runat="server" />
    
 

Samu Zhang
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
0
Samu
11/10/2008 4:02:02 AM
Reply:

Similar Artilces:

Datagrid(.net 1.1) to GridView(.net 2.0) and using the RowUpdating event how to extract the values from the controls.
Ok  This is the settings: I use a Viewgrid with only itemtemplate colums for example. <asp:TemplateField HeaderText="Test"><ItemTemplate><asp:Label id="LBL_Test" text='<%# DataBinder.Eval(Container.DataItem, "Test1") %>' runat="server" meta:resourcekey="LBL_TestResource1"></asp:Label></font></ItemTemplate> <EditItemTemplate><asp:TextBox ID="HDN_Test" Text='<%# DataBinder.Eval(Container.DataItem, "Test1") %>' Runat="server" meta:resourcekey="HDN_TestResource1" /></EditItemTemplate></asp:TemplateField>  The ...

Table Cell click event
Hi, I used to have a custom server control inhirted from TableCell control to implement click event in VS.NET 2003.  When I use the custom control in VS.NET 2003 Web application (dynamically adding to table object), everything works fine.  Below is the code from 2003 project, and everything works good in this way.                 Dim c As New MyCustomTableCell                  c.Width = 200     &nb...

Edit the cell text by clicking in the cell in datagrid control
Sir,In asp.net 2.0 application, I want to edit the cell text by clicking in the cell in datagrid control. By EditItemTemplate it is possible to edit the cell text but for that we need to click on Edit button and after edit we need to click on Update button. But this way is not accepted. Is it possible in datagrid (possibly without activex control) to click in cell and edit the value and click out of the cell to update just like windows application grid?I did not find any article on web related to this.Please help me.Thanks in advance.    &nbs...

Problem in passing the cell value to a event handlar that will be called when the cell is clicked in a datagrid
hi,  this is my code , my need is to pass the valus of the cells in the first column to a event handlar method that will be called when the cells in the second column is clicked  I am struggling for ten days , Could you please tell me a solution? <asp:DataGrid ID="DataGrid2" DataKeyField ="Form Name" runat="server" ShowHeader="False" OnItemCommand ="DataGrid2_ItemCommand" OnPageIndexChanged ="Grd_frm_history_OnPageIndexChanged" OnItemDataBound ="DataGrid2_ItemDataBound" style="vertical-align: top; tex...

Datagrid cell click event
I am attempting to figure out how to capture the click of a specific cell so that I can display a box for that cell for editing.  I do not want to edit the entire row.  I have seen lots of client-side JS that will let you display the cells value, but nothing that pushes back serverside. The proccess would be that you would click on a cell and an edit box would be displayed.  This would not display within the datagrid; instead, it would either be another window or perhaps a floating panel on the same page...  Once the change has been made, the data entered would be valida...

Table control cell click event?
I am trying to make a table as follows. 1. A header row that spans all the columns and holds the current month's name 2. The first cell in the next row is blank and the next 5 hold the days of the week Monday - Friday 3. The rest of the rows are added from a XML file. The first cell will hold a users name the rest are blank. It will essentially be a calendar but of only Monday - Friday that I am using as a IN/OUT box. My thought is that a user would click on a cell of a day that they would be off and I could change the backgroound color of the cell as a visual queue.   The pr...

Adding events to controls, e.g. adding a click event to a label control
 Hi, Is it possible to add a click event to a label control so that one can make something happen when a user clicks the label? How can it be done? One could of course use a linkbutton control, which has an in-built click event. Unfortunately a linkbutton insists on doing a postback every time it is clicked.Thank you!Regards.   Label is span control in html call javascript onclick event <span id="fkdsjfl" onclick=" ">here</span> if you want to call postback event then chk ithttp://forums.devx.com/showthread.php?t=142257 If this post...

Assigning a DataGrid cell click event handler?
Is there a click event for DataGrid cells? I understand how to add a button in a column, but if I don't really need a visual button, is there a way to assign a handler for a click event for a DataGrid cell itself (or perhaps its text)? I was kind of expecting there was something like myDataGrid.ItemClicked += new DataGridItemEventHandler(this.handleMyClick); ...or someway of assigning a handler as the item is bound with myCell.Attributes.Add() Thanks for any help. um, yeah, that's pretty much where to start. In the ItemDataBound Event, you can easily add a client scri...

how to create event handlar for a datagrid cell when it is clicked
hi,            I am showing some documents name and a link called "Download" and an icon "pdf.jpg" in my datagrid. All i need is to show the "DownLoad or save as dialog box " for a particular document when its corresponding "Download" link is clicked.  Currently my code is protected void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) {if (((e.Item.ItemType == ListItemType.Item)|| (e.Item.ItemType == ListItemType.AlternatingItem))) {if (e.Item.Cells[0...

how to add On Click event in Treeview of .Net 2?.
I can't add onClick event in my treeview. OnSelectedNodeChanged event is not fire. I hope somebody can give me a clue. Thanks in advance !! Check the autopostback property is set to true if still not working then plz paste ur code here.. Nital SoniDon't forget to MARK AS ANSWER if the post is helpful to you. Hi Soni, My TreeView don't have AutoPostBack property..How do I enter?. I really appreciate for your help. Thanks! Pe   Hi,    Try  in the NodeSelected Event of treeview.    Let me know if you got the solution. G...

Repeater Control Cell Click Event Not Firing
Hi,I am displaying values from web service in a repeater control in turn has table,rows,cell. The code extract is shown below,<asp:Repeater ID="Repeater1" runat="server">    <itemtemplate>        <tr bgcolor="white" id="">                       <td class="grd" align="justify"> <%#DataBinder.Eval(Container.DataItem,"FlightInfo")%></td>     ...

How to raise datagrid itemcommand event from a user control #2
i have a datagrid usercontrol which i have used in webform, whenever i click on linkbutton of datagrid usercontrol it didn't raise an datagrid_itemcommand event.here is the code UserControl CodeImports ItemCommand.CreateDatagridPublic Class RunTimeGrid  Inherits System.Web.UI.UserControl #Region " Web Form Designer Generated Code "   'This call is required by the Web Form Designer.  <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()   End Sub  Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid  Protected WithE...

User Control Click Event Not Working In Firefox 2
Hi,I have a user control that contains an ImageButton. I want the click event to be handled in the container page. Here's how I did it. This is the code-behind of my user control: public partial class ActionMenuItem : System.Web.UI.UserControl{ public event ImageClickEventHandler Click; protected void btnIcon_Click(object sender, ImageClickEventArgs e) { if (Click != null) Click(sender, e); }}This is the HTML source of the User Control: 1 <div class="action_menu_box <%= this.FloatCSS %>">2 <div class="gray_box">3 ...

Edit individual datagrid cells using click event
Hi All, I am developing a simple datagrid to store data with a status field. the requirement is when ever user clicks that perticular cell in that Status column (any row in that column) the display control(label) will switch to dropdownlist with 3 options. user selects any one option and that value should update and replace the dropdownlist. Its kind of spreadsheet style editing.... how to handle this. i tried to use itemdatabound event. but couldn't succeed. Please help me .  Thanks., vrnetLover  My recommendation would be to add into ItemTemplate for the "Status&...

Web resources about - DataGrid cell click event #2 - asp.net.presentation-controls

Want to preview our new DataGrid for Xamarin.Forms?
tl;dr Zumero.DataGrid is a Xamarin.Forms control for displaying data in rows and columns. If you would be interested in testing and previewing ...

Mad King DataGrid
This post is about scrolling in WPF and the egocentric DataGrid control. I’ll give the project background but if all you’re interested in is ...

Stack Overflow
Stack Exchange log in - careers - chat - meta - about - faq Questions Tags Users Badges Unanswered Ask Question Top Questions interesting 295 ...

Microsoft Silverlight - Wikipedia, the free encyclopedia
Microsoft Silverlight is an application framework for writing and running rich Internet applications , with features and purposes similar to ...

Flash Builder Plug-in for SAP Netweaver Gateway - Adobe Labs
Search Navigation Labs Home Wiki Home Technologies Alchemy Blueprint Camera Profiles and DNG Profile Editor Cirrus ColdFusion 10 DNG Codec Fireworks ...

Casaba Security » Products » X5s Testing Tool For Finding XSS Vulnerabilities
Security analysis, consulting, development and testing partners who understand your business strategy.

CodeGuru - Microsoft developers related ideas, articles, tips, tricks, comments, downloads, and so much ...
CodeGuru is where developers can come to share ideas, articles, questions, answers, tips, tricks, comments, downloads, and so much more related ...

Caliburn Micro: WPF, Silverlight, WP7 and WinRT/Metro made easy.
A small, yet powerful framework designed for WPF, Silverlight and WP7. It implements a variety of UI patterns for solving real-world problems. ...

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 11 Jul 2012

license-discuss@opensource.org: 11636: first draft of license proliferation committee report
FYI,the first draft report of the OSI's License Proliferation Committee.To join the OSI's license proliferation discuss email list, send anemail ...

Resources last updated: 12/19/2015 5:13:21 AM