Getting Control ID of buttons in Buttoncolumn in a Datagrid

  • Thread starter DotNetJunkies User
  • Start date
D

DotNetJunkies User

Hi ,
I hav a buttoncolumn(pushBackButton) in my datagrid. And on click of every button i want to call different methods(server side).

Kindly help me out..!!!!!!!!
Thnx,
Rameshwar,Govindu.
 
E

EijiTek

Based on what you've described, you don't really need to worry about the ID
of the button. You want to set the CommandName and CommandArgument (if
needed) properties of the button. In your event handler for the ItemCommand
event, test the value of the CommandName property and call the appropriate
method based on the result.

[C#]
protected void TestGrid_OnItemCommand(Object sender,
DataGridCommandEventArgs e)
{
switch(e.CommandName)
{
case "Command1":
Method1():
break;
case "Command2":
Method2();
break;
default:
Response.Write("Nothing Defined!");
break;
}
}

DotNetJunkies User said:
Hi ,
I hav a buttoncolumn(pushBackButton) in my datagrid. And on
click of every button i want to call different methods(server side).
Kindly help me out..!!!!!!!!
Thnx,
Rameshwar,Govindu.
engine supports Post Alerts, Ratings, and Searching.
 
C

Cowboy \(Gregory A. Beamer\) [MVP]

Try branching inside the routine called from the button click rather than
attempting to call different routines. In other words, you know the
reasoning behind the different events being called (first click, second
click, or similar), so you can branch based on that. For example (C#):

//At top of page (declarations)
protected int clickNumber = 0;

private void Button1_Click(Object sender, EventArgs e)
{
'Set click number higher for this click
'NOTE: can do this after, if you want 0 to be your start
clickNumber += 1;

switch(clickNumber)
{
case 1:
//Code on first click
break;
case 2:
//Code on second click
break;
case 3:
//Code on third click
break;
default:
//Code on all other clicks
break;
}
}

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
DotNetJunkies User said:
Hi ,
I hav a buttoncolumn(pushBackButton) in my datagrid. And on
click of every button i want to call different methods(server side).
Kindly help me out..!!!!!!!!
Thnx,
Rameshwar,Govindu.
engine supports Post Alerts, Ratings, and Searching.
 
E

Eliyahu Goldin

Use UniqueId property.

Eliyahu

DotNetJunkies User said:
Hi ,
I hav a buttoncolumn(pushBackButton) in my datagrid. And on
click of every button i want to call different methods(server side).
Kindly help me out..!!!!!!!!
Thnx,
Rameshwar,Govindu.
engine supports Post Alerts, Ratings, and Searching.
 

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

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top