ASP.NET Datagrid

S

Steven Van Eyck

Hi there

There are probably lots of questions being posted about datagrids, but I
can't resist... ;-)

Here's my issue:

I have an aspx page with a datagrid in which I manually declare the columns
like this:

<asp:DataGrid ID="grdCampaigns" runat="server" BorderColor="#73C6EF"
GridLines="Vertical" CellPadding="2" CellSpacing="0" Width="100%"
Font-Name="Verdana" Font-Size="6px" HeaderStyle-CssClass="tableheader"
ItemStyle-BackColor="#FFFFFF" AlternatingItemStyle-BackColor="#FFFFCC"
AutoGenerateColumns="False">

<columns>

<asp:TemplateColumn HeaderText="ID">

<itemtemplate>

<asp:Label ID="colCampaignId" runat="server"
Text='<%# Container.DataItem("ID") %>'/>

</itemtemplate>

<itemstyle HorizontalAlign="center" Width="40"/>

</asp:TemplateColumn>



<asp:TemplateColumn HeaderText="CAMPAIGN">

<itemtemplate>

<asp:TextBox ID="colCampaign" runat="server"
Text='<%# Container.DataItem("CAMPAIGN") %>' MaxLength="50" Width="290"
CssClass="dropdown"/>

</itemtemplate>

<itemstyle HorizontalAlign="center" Width="300"/>

</asp:TemplateColumn>



<asp:TemplateColumn HeaderText="mob">

<itemtemplate>

<asp:CheckBox ID="colMobile" runat="server"
Checked='<%# Container.DataItem("MOBILE") %>'/>

</itemtemplate>

<itemstyle Width="50" HorizontalAlign="center"/>

</asp:TemplateColumn>



<asp:TemplateColumn HeaderText="load">

<itemtemplate>

<asp:CheckBox ID="colLoader" runat="server"
Checked='<%# Container.DataItem("LOADER") %>'/>

</itemtemplate>

<itemstyle Width="50" HorizontalAlign="center"/>

</asp:TemplateColumn>



<asp:TemplateColumn HeaderText="EFORM">

<itemtemplate>

<asp:TextBox ID="colEform" runat="server"
Text='<%# Container.DataItem("EFORM") %>' MaxLength="255"
CssClass="dropdown" Width="370"/>

</itemtemplate>

<itemstyle HorizontalAlign="center" Width="380"/>

</asp:TemplateColumn>



<asp:TemplateColumn HeaderText="">

<itemtemplate>

<asp:LinkButton ID="btnSave" runat="server"
OnClick="doSave"/>

<img
src="../general/images/buttons/squares/save-indication.gif" border="0"/>

</asp:LinkButton>

</itemtemplate>

<itemstyle HorizontalAlign="center" Width="20"/>

</asp:TemplateColumn>



</columns>



</asp:DataGrid>


Some code behind loads the data from my backend database into the datagrid
and that is working perfectly.
During this procedure, I add an empty row in the datagrid that the user can
use to create a new record.

The problem lies in the btnSave control. When the user clicks this button, I
want my code to know which row the user wan't to update/insert, but I can't
seem to get a reference to the exact row.

Does anybody know how to tackle this ?

Many thanks
 
G

Guest

You can use, EditCommand this will help you to put a particular row in edit
mode by setting the EditItemIndex property

private void DataGrid1_EditCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex = e.Item.ItemIndex;
DataGrid1.DataBind();
}
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top