Hi
In below code Dynamic Link Button r created in Gridview RowDataBound. I want when user clicks on burron Data should get dispayed in Modal Popup Repeater
protected void gr_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType != DataControlRowType.DataRow)
return;
e.Row.Cells[0].HorizontalAlign = HorizontalAlign.Center;
for (int i = 6; i < e.Row.Cells.Count; i++)
{
var row = (DataRowView)e.Row.DataItem;
var currentPerson = row[0].ToString();
var currentDate = row.DataView.Table.Columns[i];
var commandArgument = currentPerson + ":" + currentDate;
LinkButton button = new LinkButton();
button.Text = row[i].ToString();
button.CommandName = "Select";
button.CommandArgument = commandArgument;
button.OnClientClick = "GetModuleData(this)";
}
}
}
************************
private void ShowPopUpData()
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(@"");
ClientScript.RegisterStartupScript(this.GetType(), "JSScript", sb.ToString());
}
Thanks
Ramco RamcoPosted May 17, 2023, 6:06 AM
Hi RajKiran
Can u pls explain below. Do i need to use WebMethod
// Populate the modal popup with the data
// You can use AJAX to fetch the data from the server and bind it to the repeater inside the modal popup
Thanks
Rajkiran SwainPosted May 17, 2023, 5:57 AM
To display data in a modal popup repeater when a user clicks on a dynamic link button in a GridView, you can follow these steps:
1. Add a modal popup control to your page. Make sure it has an ID assigned to it.
```html
```
2. Modify your link button creation code in the `gr_RowDataBound` event handler to include a data-toggle attribute and a data-target attribute to associate the link button with the modal popup.
```csharp
button.OnClientClick = "GetModuleData(this);";
button.Attributes["data-toggle"] = "modal";
button.Attributes["data-target"] = "#modal_form_horizontal";
```
3. In your JavaScript code, define the `GetModuleData` function to handle the click event of the link button. This function should extract the necessary data from the link button and populate the modal popup with the data.
```javascript
function GetModuleData(linkButton) {
var commandArgument = linkButton.getAttribute("data-CommandArgument");
// Extract the required data from the commandArgument string
// Populate the modal popup with the data
// You can use AJAX to fetch the data from the server and bind it to the repeater inside the modal popup
// Finally, show the modal popup
$('#modal_form_horizontal').modal('show');
}
```
4. In your code-behind, modify the `ShowPopUpData` method to only show the modal popup without any other logic.
```csharp
private void ShowPopUpData()
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "ShowPopUp", "$('#modal_form_horizontal').modal('show');", true);
}
```
Ensure that you have registered the `ScriptManager` control in your page.
With these modifications, when the user clicks on the dynamic link button in the GridView, the `GetModuleData` function will be called. It will extract the necessary data, populate the modal popup with the data (using AJAX if required), and show the modal popup using the `$('#modal_form_horizontal').modal('show');` code.