DataGrid Row click event to get value of column

S

sureshsolution

Hi !

I am new to this. Hope everybody can help to work efficient on this.
Recently i am facing a problem (may be simple) and i request all to
guide me to solve.
The problem is as follows:

I am having mygrid.aspx page which contains one datagrid which is
populating values from student database.
Datagrid has item label id "lblresultsysid"
I write code onItemDatabound event to fire a simple javascript display
the lblresultsysid value

Now what i exactly need is the value of lblresultsysid or sid in
javascript has to retrive in my code behind file (mygrid.aspx.cs)
function processstuden(string studentresultid) for further processing .
Please help.



<asp:datagrid id="DataGrid1" runat="server" AllowCustomPaging="True"
AllowPaging="True" PageSize="10"
PagerStyle-Mode="NumericPages"
AlternatingItemStyle-BackColor="#F1F1F1" CellPadding="2"
HeaderStyle-BackColor="#F3F3EA"
GridLines="None" BorderWidth="0" DataKeyField="ResultsysID"
AutoGenerateColumns="False" OnItemDataBound="test">
<Columns>
<asp:TemplateColumn HeaderText="ID">
<ItemTemplate>
<asp:Label ID="lblResultSysID" Visible="true" Text='<%#
DataBinder.Eval(Container.DataItem,"resultsysid") %>' Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="StudentID" HeaderText="Student
ID"></asp:BoundColumn>
<asp:BoundColumn DataField="RollNo" HeaderText="Roll
No"></asp:BoundColumn>
<asp:BoundColumn DataField="StudentName" HeaderText="Student
Name"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Appeared">
<ItemTemplate>
<asp:DropDownList id="ddlAppeared" runat="server"
AutoPostBack ="True" DataSource ='<%# LoadAppearedValues() %>'
OnSelectedIndexChanged ="AppearedNo" Width="75">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Marks Obtained">
<ItemTemplate>
<asp:TextBox id="txtMarksObtained" BorderWidth="1"
BorderColor= "#808080" Width="50" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.MarksObtained") %>'>
</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn Visible="true">
<HeaderTemplate>
<Input id="checkAll" type="checkbox" style="CURSOR: hand">
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkDel" Runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>

protected void test(object sender, DataGridItemEventArgs e)
{
lblStatus.Text = "test";
Label lblRowID;
TableRow dgRow;

switch (e.Item.ItemType )
{
case ListItemType.Item :
{


lblRowID = (Label)e.Item.FindControl("lblResultsysID");
dgRow =
(TableRow)e.Item.FindControl("lblResultsysID").Parent.Parent;
dgRow.Attributes.Add ("OnDblClick", "ShowDetails(" + lblRowID.Text
+ ");");
break;
};
case ListItemType.AlternatingItem :
{


lblRowID = (Label)e.Item.FindControl("lblResultsysID");

dgRow =
(TableRow)e.Item.FindControl("lblResultsysID").Parent.Parent;
dgRow.Attributes.Add ("OnDblClick", "ShowDetails(" + lblRowID.Text
+ ");");





break;
};
}



<script language="javascript" type ="text/javascript" >
function ShowDetails(sid)
{
alert ("You selected \n " + unescape(sid));



}
</script>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top